2017-06-11 52 views
0

我從github上下載了一個項目的測試,當我要運行的應用程序,我的圖片鏈接得到這個錯誤Error Report沒有這樣的文件或目錄C++

應用gradle這個:

apply plugin: 'com.android.model.application' 

model { 
repositories { 
    libs(PrebuiltLibraries) { 
     prebuilt { 
      headers.srcDir "../../../package/include" 
      binaries.withType(SharedLibraryBinary) { 
       sharedLibraryFile = file("../../../package/Android/libs/armeabi-v7a/libEasyAR.so") 
      } 
     } 
    } 
} 
android { 
    compileSdkVersion = 25 
    buildToolsVersion = "25.0.2" 

    defaultConfig.with { 
     applicationId = "com.jerome.unitydemo" 
     minSdkVersion.apiLevel = 15 
     targetSdkVersion.apiLevel = 22 
     versionCode = 1 
     versionName = "1.0" 
    } 



    sources { 
     main { 

      jni { 
       dependencies { 
        library "prebuilt" 
       } 

      } 
     } 
    } 
} 
android.buildTypes { 
    release { 
     minifyEnabled = false 
     proguardFiles.add(file("proguard-rules.pro")) 
    } 
} 
android.ndk { 
    moduleName = "HelloARVideoNative" 
    cppFlags.add("-I${file("../../../package/include")}".toString()) 
    cppFlags.add("-DANDROID") 
    cppFlags.add("-fexceptions") 
    cppFlags.add("-frtti") 
    stl = "gnustl_static" 
    ldLibs.add("log") 
    ldLibs.add("GLESv2") 
} 

android.productFlavors { 
    create("arm") { 
     ndk.with { 
      abiFilters.add("armeabi-v7a") 
     } 
    } 

} 
} 

dependencies { 
compile fileTree(include: ['*.jar'], dir: 'libs') 
compile 'com.android.support:appcompat-v7:25.1.1' 
} 

Android.mk

LOCAL_PATH_TOP := $(call my-dir) 
EASYAR_PACKAGE_PATH := $(LOCAL_PATH_TOP)/../../../../../../package 

include $(CLEAR_VARS) 
LOCAL_PATH := $(EASYAR_PACKAGE_PATH)/Android/libs/armeabi-v7a 
LOCAL_MODULE:=libEasyAR 
LOCAL_SRC_FILES:=libEasyAR.so 
include $(PREBUILT_SHARED_LIBRARY) 

include $(CLEAR_VARS) 
LOCAL_PATH := $(LOCAL_PATH_TOP) 
LOCAL_C_INCLUDES += $(EASYAR_PACKAGE_PATH)/include 
LOCAL_CPPFLAGS += -DANDROID 
LOCAL_LDLIBS += -llog -lGLESv2 
LOCAL_SHARED_LIBRARIES += libEasyAR 
LOCAL_CPP_EXTENSION := .cc 
LOCAL_MODULE := libHelloARNative 
LOCAL_SRC_FILES := ar.cc helloarvideo.cc renderer.cc 
include $(BUILD_SHARED_LIBRARY) 

Application.mk

APP_OPTIM := release 
APP_PLATFORM := android-17 
APP_STL := gnustl_static 
APP_ABI := armeabi-v7a 
APP_MODULES := HelloARNative 
NDK_TOOLCHAIN := arm-linux-androideabi-4.9 

而這所有的文件在我的JNIProject structure

我與這個錯誤掙扎,沒有任何結果,請幫助。

ar.hpp

#ifndef __EASYAR_SAMPLE_UTILITY_AR_H__ 
#define __EASYAR_SAMPLE_UTILITY_AR_H__ 

#include "easyar/camera.hpp" 
#include "easyar/imagetracker.hpp" 
#include "easyar/augmenter.hpp" 
#include "easyar/imagetarget.hpp" 
#include "easyar/frame.hpp" 
#include "easyar/player.hpp" 
#include "easyar/utility.hpp" 
#include <string> 

namespace EasyAR{ 
namespace samples{ 

class AR 
{ 
public: 
AR(); 
virtual ~AR(); 
virtual bool initCamera(); 
virtual void loadFromImage(const std::string& path); 
virtual void loadFromJsonFile(const std::string& path, const std::string&  targetname); 
virtual void loadAllFromJsonFile(const std::string& path); 
virtual bool start(); 
virtual bool stop(); 
virtual bool clear(); 

virtual void initGL(); 
virtual void resizeGL(int width, int height); 
virtual void render(); 
void setPortrait(bool portrait); 
protected: 
CameraDevice camera_; 
ImageTracker tracker_; 
Augmenter augmenter_; 
bool portrait_; 
Vec4I viewport_; 
}; 

class ARVideo { 
public: 
ARVideo(); 
~ARVideo(); 

void openVideoFile(const std::string& path, int texid); 
void openTransparentVideoFile(const std::string& path, int texid); 
void openStreamingVideo(const std::string& url, int texid); 

void setVideoStatus(VideoPlayer::Status status); 
void onFound(); 
void onLost(); 
void seek(int pos); 
int currentPosition(); 
int duration(); 
bool pause(); 
bool play(); 
void update(); 

class CallBack : public VideoPlayerCallBack 
{ 
public: 
    CallBack(ARVideo* video); 
    void operator() (VideoPlayer::Status status); 
private: 
    ARVideo* video_; 
}; 

private: 
VideoPlayer player_; 
bool prepared_; 
bool found_; 
CallBack* callback_; 
std::string path_; 
}; 

} 
} 
#endif 

ar.cc

#include "ar.hpp" 
#include <algorithm> 
#ifdef ANDROID 
#include <android/log.h> 
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "EasyAR", __VA_ARGS__) 
#else 
#define LOGI(...) printf(__VA_ARGS__) 
#endif 

namespace EasyAR{ 
namespace samples{ 

class HelloCallBack : 
public TargetLoadCallBack 
{ 
public: 
virtual ~HelloCallBack() { 
}; 
virtual void operator() (const Target target, const bool status) 
{ 
LOGI("load target: %s (%d) %s\n", target.name(), target.id(), status ? "success" : "fail"); 
delete this; 
} 
}; 

AR::AR() 
{ 
portrait_ = false; 
} 

AR::~AR() 
{ 
clear(); 
} 

bool AR::initCamera() 
{ 
bool status = true; 
status &= camera_.open(); 
camera_.setSize(Vec2I(1280, 720)); 
status &= tracker_.attachCamera(camera_); 
status &= augmenter_.attachCamera(camera_); 
return status; 
} 


void AR::loadFromImage(const std::string& path) 
{ 
ImageTarget target; 
std::string jstr = "{\n" 
" \"images\" :\n" 
" [\n" 
" {\n" 
"  \"image\" : \"" + path + "\",\n" 
"  \"name\" : \"" + path.substr(0, path.find_first_of(".")) + "\"\n" 
" }\n" 
" ]\n" 
"}"; 
target.load(jstr.c_str(), EasyAR::kStorageAssets | EasyAR::kStorageJson); 
tracker_.loadTarget(target, new HelloCallBack()); 
} 

void AR::loadFromJsonFile(const std::string& path, const std::string& targetname) 
{ 
ImageTarget target; 
target.load(path.c_str(), EasyAR::kStorageAssets, targetname.c_str()); 
tracker_.loadTarget(target, new HelloCallBack()); 
} 

void AR::loadAllFromJsonFile(const std::string& path) 
{ 
TargetList targets = ImageTarget::loadAll(path.c_str(), EasyAR::kStorageAssets); 
for (int i = 0; i < targets.size(); ++i) { 
tracker_.loadTarget(targets[i], new HelloCallBack()); 
} 
} 

bool AR::start() 
{ 
bool status = true; 
status &= camera_.start(); 
camera_.setFocusMode(CameraDevice::kFocusModeContinousauto); 
status &= tracker_.start(); 
return status; 
} 



bool AR::stop() 
{ 
bool status = true; 
status &= tracker_.stop(); 
status &= camera_.stop(); 
return status; 
} 

bool AR::clear() 
{ 
bool status = true; 
status &= stop(); 
status &= camera_.close(); 
camera_.clear(); 
tracker_.clear(); 
augmenter_.clear(); 
return status; 
} 

void AR::resizeGL(int width, int height) 
{ 
Vec2I size = Vec2I(1, 1); 
if (camera_.isOpened()) 
size = camera_.size(); 
if (size[0] == 0 || size[1] == 0) 
return; 
if (portrait_) 
std::swap(size[0], size[1]); 
float scaleRatio = std::max((float)width/(float)size[0], (float)height/(float)size[1]); 
Vec2I viewport_size = Vec2I((int)(size[0] * scaleRatio), (int)(size[1] * scaleRatio)); 
viewport_ = Vec4I(0, height - viewport_size[1], viewport_size[0],  viewport_size[1]); 
    } 

void AR::initGL() 
{ 

} 

void AR::render() 
{ 

} 

void AR::setPortrait(bool portrait) 
{ 
portrait_ = portrait; 
} 

ARVideo::ARVideo() 
{ 
prepared_ = false; 
found_ = false; 
callback_ = NULL; 
} 

ARVideo::~ARVideo() 
{ 
player_.close(); 
if (callback_) 
delete callback_; 
} 

void ARVideo::openVideoFile(const std::string& path, int texid) 
{ 
if (!callback_) 
callback_ = new CallBack(this); 
path_ = path; 
player_.setRenderTexture(texid); 
player_.setVideoType(VideoPlayer::kVideoTypeNormal); 
player_.open(path.c_str(), kStorageAssets, callback_); 

} 

void ARVideo::openTransparentVideoFile(const std::string& path, int texid) 
{ 
if (!callback_) 
callback_ = new CallBack(this); 
path_ = path; 
player_.setRenderTexture(texid); 
player_.setVideoType(VideoPlayer::kVideoTypeTransparentSideBySide); 
player_.open(path.c_str(), kStorageAssets, callback_); 
} 

void ARVideo::openStreamingVideo(const std::string& url, int texid) 
{ 
if (!callback_) 
callback_ = new CallBack(this); 
path_ = url; 
player_.setRenderTexture(texid); 
player_.setVideoType(VideoPlayer::kVideoTypeNormal); 
player_.open(url.c_str(), kStorageAbsolute, callback_); 
} 

void ARVideo::setVideoStatus(VideoPlayer::Status status) 
{ 
LOGI("video: %s (%d)\n", path_.c_str(), status); 
if (status == VideoPlayer::kVideoReady) { 
prepared_ = true; 
if (found_) 
player_.play(); 
} 
if (status == VideoPlayer::kVideoCompleted) { 
if (found_) 
player_.play(); 
} 
} 

void ARVideo::onFound() 
{ 
found_ = true; 
if (prepared_) { 
player_.play(); 
} 
} 

void ARVideo::onLost() 
{ 
found_ = false; 
if (prepared_) 
player_.pause(); 
} 
int ARVideo::duration(){ 
if (prepared_) { 
return player_.duration(); 
}else{ 
return 0; 
} 
} 
int ARVideo::currentPosition(){ 
if (prepared_) { 
return player_.currentPosition(); 
}else{ 
return 0; 
} 
} 
bool ARVideo::pause(){ 
if (prepared_) 
player_.pause(); 
return false; 
} 

bool ARVideo::play(){ 
if (prepared_) 
return player_.play(); 
return false; 
} 

void ARVideo::seek(int pos){ 
if(prepared_){ 
    player_.seek(pos); 
} 
} 


void ARVideo::update() 
{ 
player_.updateFrame(); 
} 

ARVideo::CallBack::CallBack(ARVideo* video) 
{ 
video_ = video; 
} 

void ARVideo::CallBack::operator() (VideoPlayer::Status status) 
{ 
video_->setVideoStatus(status); 
} 

} 
} 

renderer.hpp

#ifndef __EASYAR_SAMPLE_UTILITY_SIMPLERENDERER_H__ 
#define __EASYAR_SAMPLE_UTILITY_SIMPLERENDERER_H__ 

#include "easyar/matrix.hpp" 

namespace EasyAR{ 
namespace samples{ 

class VideoRenderer 
{ 
public: 
void init(); 
void render(const Matrix44F& projectionMatrix, const Matrix44F& cameraview, Vec2F size); 
unsigned int texId(); 
private: 
unsigned int program_box; 
int pos_coord_box; 
int pos_tex_box; 
int pos_trans_box; 
int pos_proj_box; 
unsigned int vbo_coord_box; 
unsigned int vbo_tex_box; 
unsigned int vbo_faces_box; 
unsigned int texture_id; 
}; 

} 
} 
#endif 

渲染er.cc

#include "renderer.hpp" 
#if defined __APPLE__ 
#include <OpenGLES/ES2/gl.h> 
#else 
#include <GLES2/gl2.h> 
#endif 

const char* box_video_vert="uniform mat4 trans;\n" 
     "uniform mat4 proj;\n" 
     "attribute vec4 coord;\n" 
     "attribute vec2 texcoord;\n" 
     "varying vec2 vtexcoord;\n" 
     "\n" 
     "void main(void)\n" 
     "{\n" 
     " vtexcoord = texcoord;\n" 
     " gl_Position = proj*trans*coord;\n" 
     "}\n" 
     "\n" 
; 

const char* box_video_frag="#ifdef GL_ES\n" 
     "precision highp float;\n" 
     "#endif\n" 
     "varying vec2 vtexcoord;\n" 
     "uniform sampler2D texture;\n" 
     "\n" 
     "void main(void)\n" 
     "{\n" 
     " gl_FragColor = texture2D(texture, vtexcoord);\n" 
     "}\n" 
     "\n" 
; 

namespace EasyAR{ 
namespace samples{ 

void VideoRenderer::init() 
{ 
    program_box = glCreateProgram(); 
    GLuint vertShader = glCreateShader(GL_VERTEX_SHADER); 
    glShaderSource(vertShader, 1, &box_video_vert, 0); 
    glCompileShader(vertShader); 
    GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER); 
    glShaderSource(fragShader, 1, &box_video_frag, 0); 
    glCompileShader(fragShader); 
    glAttachShader(program_box, vertShader); 
    glAttachShader(program_box, fragShader); 
    glLinkProgram(program_box); 
    glUseProgram(program_box); 
    pos_coord_box = glGetAttribLocation(program_box, "coord"); 
    pos_tex_box = glGetAttribLocation(program_box, "texcoord"); 
    pos_trans_box = glGetUniformLocation(program_box, "trans"); 
    pos_proj_box = glGetUniformLocation(program_box, "proj"); 

    glGenBuffers(1, &vbo_coord_box); 
    glBindBuffer(GL_ARRAY_BUFFER, vbo_coord_box); 
    const GLfloat cube_vertices[4][3] = {{1.0f/2, 1.0f/2, 0.f},{1.0f/2, -1.0f/2, 0.f},{-1.0f/2, -1.0f/2, 0.f},{-1.0f/2, 1.0f/2, 0.f}}; 
    glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_DYNAMIC_DRAW); 

    glGenBuffers(1, &vbo_tex_box); 
    glBindBuffer(GL_ARRAY_BUFFER, vbo_tex_box); 
    const GLubyte cube_vertex_texs[4][2] = {{0, 0},{0, 1},{1, 1},{1, 0}}; 
    glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertex_texs), cube_vertex_texs, GL_STATIC_DRAW); 

    glGenBuffers(1, &vbo_faces_box); 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_faces_box); 
    const GLushort cube_faces[] = {3, 2, 1, 0}; 
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_faces), cube_faces, GL_STATIC_DRAW); 

    glUniform1i(glGetUniformLocation(program_box, "texture"), 0); 
    glGenTextures(1, &texture_id); 
    glBindTexture(GL_TEXTURE_2D, texture_id); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
} 

void VideoRenderer::render(const Matrix44F& projectionMatrix, const Matrix44F& cameraview, Vec2F size) 
{ 
    glBindBuffer(GL_ARRAY_BUFFER, vbo_coord_box); 
    const GLfloat cube_vertices[4][3] = {{size[0]/2, size[1]/2, 0.f},{size[0]/2, -size[1]/2, 0.f},{-size[0]/2, -size[1]/2, 0.f},{-size[0]/2, size[1]/2, 0.f}}; 
    glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_DYNAMIC_DRAW); 

    glEnable(GL_BLEND); 
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
    glEnable(GL_DEPTH_TEST); 
    glUseProgram(program_box); 
    glBindBuffer(GL_ARRAY_BUFFER, vbo_coord_box); 
    glEnableVertexAttribArray(pos_coord_box); 
    glVertexAttribPointer(pos_coord_box, 3, GL_FLOAT, GL_FALSE, 0, 0); 
    glBindBuffer(GL_ARRAY_BUFFER, vbo_tex_box); 
    glEnableVertexAttribArray(pos_tex_box); 
    glVertexAttribPointer(pos_tex_box, 2, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0); 
    glUniformMatrix4fv(pos_trans_box, 1, 0, cameraview.data); 
    glUniformMatrix4fv(pos_proj_box, 1, 0, projectionMatrix.data); 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_faces_box); 
    glActiveTexture(GL_TEXTURE0); 
    glBindTexture(GL_TEXTURE_2D, texture_id); 
    glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, 0); 
    glBindTexture(GL_TEXTURE_2D, 0); 
} 

unsigned int VideoRenderer::texId() 
{ 
    return texture_id; 
} 

} 
} 

我認爲這是一個很大的代碼,但爲了得到解決,感謝你的幫助。

+1

看錯誤日誌轉到output.txt文件的路徑並複製粘貼日誌作爲代碼在這裏 –

+0

你能找到下面的地址「請參閱日誌編譯」output.txt文件地址 –

+0

發佈.cc文件和.hpp文件的代碼可能有幫助 –

回答

0

嘗試下面的事情 檢查EasyAR.jar文件的路徑,並在這兩個.HPP文件包含語句(除了#include <string>)添加這樣app/libs/armeabi-v7a/easyar/camera路徑在這裏的應用程序是libs文件夾的父目錄(如果該文件夾名稱不是應用程序)

發生了什麼事? 您的.hpp文件沒有從EasyAR.jar獲取它包含的文件的路徑,如果上述方法不起作用,請將路徑更改回#include easyar/...,並將jar文件(EasyAR.jar)放入jni目錄。 告訴我它是否有效

+0

謝謝,但它不起作用^^,如果你想在這裏測試項目這是[鏈接](https://github.com/Jerome-MJ/EasyARVideo) – john

相關問題