- Home /
Question by
awwadawwad803 · Feb 10, 2018 at 08:51 PM ·
cameranative pluginc++opencv
Can't open device camera with Native plugins using OpenCV and c++.
Hi,
I breack my head trying solving this problem but I couldn't, so I post it here for help.
I am trying to use Native plugins to use OpenCV libraries and using c++ language with unity. I created CallNativeCode file which invokes another file which is the native plugins "HandGestureNative.cpp". Inside "HandGestureNative.cpp" I am trying to create VideoCapture and open the camera, but the camera is not openning. I made sure that all the opencv dependeinces file has been delared in the file. Please check the following code inside the "HandGestureNative.cpp":
#include "HandGestureNative.h"
#include <opencv2\core.hpp>
//opencv
#include<opencv\cv.hpp>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <string>
#include <sstream>
//C++
#include <iostream>
#include <sstream>
using namespace cv;
using namespace std;
// Global variables
Mat temp;
float result = 0.0;
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "HandGestureNative", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "HandGestureNativex`", __VA_ARGS__))
extern "C" {
float HandGestureNative::HandGestureCall()
{
//Creating camera and assign it to camera 0;
VideoCapture capture;
capture.open(0);
capture >> temp;
if (capture.isOpened()) { result = 5.5; }
else { result = 1.5; }
return result;
}
}
Always the return result is 1.5, which means that the camera is not open.
Please help and Thank you :).
Comment