forked from sjfricke/OpenCV-NDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CV_Main.h
117 lines (90 loc) · 2.82 KB
/
CV_Main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef OPENCV_NDK_CV_MAIN_H
#define OPENCV_NDK_CV_MAIN_H
// Android
#include <android/asset_manager.h>
#include <android/native_window.h>
#include <jni.h>
// OpenCV
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/features2d.hpp>
// OpenCV-NDK App
#include "Image_Reader.h"
#include "Native_Camera.h"
#include "Util.h"
// C Libs
#include <unistd.h>
#include <time.h>
// STD Libs
#include <cstdlib>
#include <string>
#include <vector>
#include <thread>
class CV_Main {
public:
CV_Main();
~CV_Main();
CV_Main(const CV_Main& other) = delete;
CV_Main& operator=(const CV_Main& other) = delete;
// Lets us know when app has started passing in VM info
void OnCreate(JNIEnv* env, jobject caller_activity);
// TODO
// Disconnect from service
void OnPause();
// TODO
// Cleanup
void OnDestroy();
// Cache the Java VM used from the Java layer.
void SetJavaVM(JavaVM* pjava_vm) { java_vm = pjava_vm; }
// sets Surface buffer reference pointer
void SetNativeWindow(ANativeWindow* native_indow);
// sets Surface buffer reference pointer
void SetAssetManager(AAssetManager* asset_manager) {
m_aasset_manager = asset_manager;
};
void SetUpCamera();
void CameraLoop();
void FaceDetect(cv::Mat &frame);
void RunCV();
void HaltCamera();
void FlipCamera();
private:
// Cached Java VM, caller activity object
JavaVM* java_vm;
jobject calling_activity_obj;
jmethodID on_callback;
// holds native window to write buffer too
ANativeWindow* m_native_window;
// buffer to hold native window when writing to it
ANativeWindow_Buffer m_native_buffer;
// Camera variables
Native_Camera* m_native_camera;
camera_type m_selected_camera_type = BACK_CAMERA; // Default
// Image Reader
ImageFormat m_view{0, 0, 0};
Image_Reader* m_image_reader;
AImage* m_image;
volatile bool m_camera_ready;
// used to hold reference to assets in assets folder
AAssetManager* m_aasset_manager;
// for timing OpenCV bottlenecks
clock_t start_t, end_t;
double total_t;
// Used to detect up and down motion
bool scan_mode;
// OpenCV values
cv::Mat display_mat;
// Currently no way of getting file string for load() call, need to manually
// store the assents in the sdcard and grab them from there
cv::String face_cascade_name = "/sdcard/Download/opencv/haarcascade_frontalface_alt.xml";
cv::String eyes_cascade_name = "/sdcard/Download/opencv/haarcascade_eye_tree_eyeglasses.xml";
cv::CascadeClassifier face_cascade;
cv::CascadeClassifier eyes_cascade;
cv::Scalar CV_PURPLE = cv::Scalar ( 255, 0, 255 );
cv::Scalar CV_RED = cv::Scalar ( 255, 0, 0 );
cv::Scalar CV_GREEN = cv::Scalar ( 0, 255, 0 );
cv::Scalar CV_BLUE = cv::Scalar ( 0, 0, 255 );
bool m_camera_thread_stopped = false;
};
#endif // OPENCV_NDK_CV_MAIN_H