BitmapToolkit Scol plugin
CameraInputAndroid.h
Go to the documentation of this file.
1#ifndef __BTK_CAMERAINPUT_ANDROID_H__
2#define __BTK_CAMERAINPUT_ANDROID_H__
3
4#include <opencv2/opencv.hpp>
5#include <vector>
6#include <utility>
7#include <boost/bind.hpp>
8#include "ICameraInput.h"
9
10#ifdef BT_USE_LIBUVC
11 #include "libuvc/libuvc.h"
12#endif
13
18{
19public:
20 static const int CAMERA_FACING_BACK;
21 static const int CAMERA_FACING_FRONT;
22 static const std::string android_package;
23
24private:
25 bool mUpdated;
26 bool mIsOpen;
27 struct android_app* mApp;
28 int mIndex;
29 cv::Size mSize;
30protected:
31 cv::Mat mFrameBuffer;
32 cv::Mat mFrameRGB;
33
34 struct jmethodbox
35 {
36 jmethodID method;
37 jobject instance;
38 jclass clazz;
39 };
40
41 void initJava();
42 jmethodbox grabMethod(JNIEnv* env, const char* name, const char* signature);
43
44public:
47
48 void startPreview(int width, int height, int index);
50 void torchOn();
51 void torchOff();
54 bool isPortrait();
55 bool isOpen();
56 cv::Size getPreviewSize();
57 cv::Size getSize();
58 bool setFocusPoint(int x, int y);
59 cv::Mat grabFrame();
60};
61
62#ifdef BT_USE_LIBUVC
66class CameraUvcAndroid
67{
68public:
69 uvc_frame_t* mFrameConv;
70 cv::Mat mFrameBuffer;
71 cv::Mat mFrameRGB;
72 bool mUpdated;
73
74private:
75 bool mIsOpen;
76 int mIndex;
77 cv::Size mSize;
78 struct android_app* mApp;
79
80 uvc_context_t* mUvcCtx;
81 uvc_device_handle_t* mUvcDevh;
82protected:
83 void initJava();
84
85public:
86 CameraUvcAndroid();
87 ~CameraUvcAndroid();
88
89 static void streamCb(uvc_frame_t *frame, void *ptr);
90 bool checkCameraPermission();
91 void startPreview(int width, int height, int index);
92 void stopPreview();
93 bool isOpen();
94 bool isValid();
95 cv::Size getSize();
96 cv::Mat grabFrame();
97
98
99};
100#endif //BT_USE_LIBUVC
101
105class CameraInputAndroid : public ICameraInput
106{
107private:
108 cv::Size mBufferSize;
109 cv::Mat mFrameCached;
111
112#ifdef BT_USE_LIBUVC
113 bool mUsbMode;
114 CameraUvcAndroid* mUVC;
115#endif
116
117 bool mInitializing;
118
119public:
120
123
124 virtual bool Initialize();
125 virtual void Close();
126 virtual bool IsOpened();
127 virtual cv::Mat UpdateImage();
128
129 virtual int GetWidth();
130 virtual int GetHeight();
131 virtual void SetSize(int width, int height);
132
133 virtual bool TakeSnapshot(std::string path);
134 virtual void RenderToScreen();
135 virtual bool SetFocusPoint(int x, int y);
136 virtual void SetTorchState(bool state);
137};
138
139#endif
bool setFocusPoint(int x, int y)
void startPreview(int width, int height, int index, bool recordingHint)
static const int CAMERA_FACING_FRONT
jmethodbox grabMethod(JNIEnv *env, const char *name, const char *signature)
static const int CAMERA_FACING_BACK
static const std::string android_package
cv::Size getPreviewSize()
Concrete implementation of ICameraInput using Android API.
virtual cv::Mat UpdateImage()
virtual void SetSize(int width, int height)
virtual bool IsOpened()
virtual int GetHeight()
virtual bool Initialize()
virtual void SetTorchState(bool state)
virtual void Close()
CameraInputAndroid(int index)
virtual bool TakeSnapshot(std::string path)
virtual void RenderToScreen()
virtual int GetWidth()
virtual bool SetFocusPoint(int x, int y)
Interface for camera management. Concrete classes are written for Windows, Android and OpenCV native ...