Previous blog "Based on Dragonboard410c android system to achieve USB camera image preview", we realized how to preview the USB camera image on 410c android system, based on this, we use the openncv library to achieve human eye recognition function . Figure 1. Dragonboard410c development board (android system) Figure 2. Display Figure 3. HDMI cable Figure 4. Logitech C525 (usb camera) 1. Download address: http://opencv.org/downloads.html 2. Migration steps: You can refer to the Android OpenCV method case, including how to achieve the overall migration by omitting openncv_manger.apk. 3. After setting up the environment, the most important thing is to join our uploaded routine: Eye_recogniTIon.rar, and compile and run (the official website opencv does not provide this feature, the author is selfless dedication to everyone). Download address: http://pan.baidu.com/s/1jIGz3dO vape disposable,vape device for vaping,vape device for smoking Shenzhen Aierbaita Technology Co., Ltd. , https://www.aierbaitavape.com
Realizing human eye recognition function based on Dragonboard 410c android system
#include
#include
#include
#include
#include
#include
#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__()}" );
}
}
Â
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart
(JNIEnv * jenv, jclass, jlong thiz)
{
Try
{
(( DetectionBasedTracker * ) thiz ) -> run ();
}
Catch ( cv :: Exception e )
{
LOGD ( "nativeStart 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 ( "nativeStart catched unknown exception" );
jclass je = jenv -> FindClass ( "java / lang / Exception");
Jenv -> ThrowNew ( je , "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}" );
}
}
Â
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop
(JNIEnv * jenv, jclass, jlong thiz)
{
Try
{
(( DetectionBasedTracker * ) thiz ) -> stop ();
}
Catch ( cv :: Exception e )
{
LOGD ( "nativeStop 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 ( "nativeStop catched unknown exception" );
jclass je = jenv -> FindClass ( "java / lang / Exception");
Jenv -> ThrowNew ( je , "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}" );
}
}
Â
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize
(JNIEnv * jenv, jclass, jlong thiz, jint faceSize)
{
Try
{
If ( faceSize > 0 )
{
DetectionBasedTracker :: Parameters DetectorParams = \
(( DetectionBasedTracker * ) thiz ) -> getParameters ();
DetectorParams . minObjectSize = faceSize ;
(( DetectionBasedTracker * ) thiz ) -> setParameters ( DetectorParams );
}
}
Catch ( cv :: Exception e )
{
LOGD ( "nativeStop 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 ( "nativeSetFaceSize catched unknown exception" );
jclass je = jenv -> FindClass ( "java / lang / Exception");
Jenv -> ThrowNew ( je , "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}" );
}
}
Â
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect
(JNIEnv * jenv, jclass, jlong thiz, jlong imageGray, jlong faces)
{
Try
{
Vector < Rect > RectFaces ;
(( DetectionBasedTracker * ) thiz ) -> process ( * (( Mat * ) imageGray ));
(( DetectionBasedTracker * ) thiz ) -> getObjects ( RectFaces );
vector_Rect_to_Mat ( RectFaces , * (( Mat * ) faces ));
}
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 ( "nativeDetect catched unknown exception" );
jclass je = jenv -> FindClass ( "java / lang / Exception");
Jenv -> ThrowNew ( je , "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}" );
}
}
Â