基于Dragonboard 410c android系统实现人的眼球识别功能
上一篇博客《基于Dragonboard410c android系统实现USB camera图像预览》,我们实现了如何在410c android系统上进行USB camera图像的预览功能,本文在此基础上,我们借助openncv库,实现人的眼球识别功能。
一 准备工具:
图1.Dragonboard410c开发板(android系统)
图2.显示器
图3.HDMI线
图4.罗技C525(usb camera)
二 移植opencv库:
1.下载地址:http://opencv.org/downloads.html
2.移植步骤:大家可以参照 Android 使用OpenCV的方法案例,包括如何可以通过省略openncv_manger.apk的方式实现整体移植。
3.搭好环境后,最主要是加入我们上传的例程:Eye_recogniTIon.rar,并编译运行(官网的opencv可不提供这个功能,笔者可是无私奉献给大家哈)。
三 关键代码:
#include <DetecTIonBasedTracker_jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/contrib/detecTIon_based_tracker.hpp>
#include <string>
#include <vector>
#include <android/log.h>
#define LOG_TAG "FaceDetecTIon/DetectionBasedTracker"
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
using namespace std;
using namespace cv;
inline void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
{
mat = Mat(v_rect, true);
}
JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject
(JNIEnv * jenv, jclass, jstring jFileName, jint faceSize)
{
const char* jnamestr = jenv->GetStringUTFChars(jFileName, NULL);
string stdFileName(jnamestr);
jlong result = 0;
try
{
DetectionBasedTracker::Parameters DetectorParams;
if (faceSize > 0)
DetectorParams.minObjectSize = faceSize;
result = (jlong)new DetectionBasedTracker(stdFileName, DetectorParams);
}
catch(cv::Exception e)
{
LOGD("nativeCreateObject catched cv::Exception: %s", e.what());
jclass je = jenv->FindClass("org/opencv/core/CvException");
if(!je)
je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, e.what());
}
catch (...)
{
LOGD("nativeCreateObject catched unknown exception");
jclass je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
return 0;
}
return result;
}
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject
(JNIEnv * jenv, jclass, jlong thiz)
{
try
{
((DetectionBasedTracker*)thiz)->stop();
delete (DetectionBasedTracker*)thiz;
}
catch(cv::Exception e)
{
LOGD("nativeestroyObject catched cv::Exception: %s", e.what());
jclass je = jenv->FindClass("org/opencv/core/CvException");
if(!je)
je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, e.what());
}
catch (...)
{
LOGD("nativeDestroyObject catched unknown exception");
jclass je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
}
}
="line" id="LC78"> JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart
="line" id="LC79"> (JNIEnv * jenv, jclass, jlong thiz) ="line" id="LC80"> { ="line" id="LC81"> try ="line" id="LC82"> { ="line" id="LC83"DragonBoard 410c 眼球识别 Android 相关文章: