videopipe.h 5.75 KB
Newer Older
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
#ifndef _VIDEOPIPE_H_
#define _VIDEOPIPE_H_

#include <vector>
#include <map>
#include <string>

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>


namespace libvideopipe 
{
	#define	WM_AI_VIDEO_FOOD_PIPE_MARK_EMPTY							0x10020001         // 输入temp为空
	#define	WM_AI_VIDEO_FOOD_PIPE_INPUT_FRAME_EMPTY						0x10020002         // 输入input数据为空
	#define	WM_AI_VIDEO_FOOD_PIPE_INPUT_FRAME_SIZE_SMALLER_THAN_MARK	0x10020003         // 输入input数据尺寸比mark小
	#define	WM_AI_VIDEO_MOTION_PIPE_INPUT_FRAME_EMPTY					0x10020004
	#define	WM_AI_VIDEO_DEPTH_PIPE_INPUT_FRAME_EMPTY					0x10020005
	#define	WM_AI_VIDEO_DEPTH_PIPE_INPUT_PARAM_ERROR					0x10020006

	// 视频流回调函数申明
	typedef void (*VideoPipeCallback)(const char* data, int len, void* user);

//*****************************************
//food
//*****************************************
	struct FOOD_VIDEOPIPE_INPUT
	{
		unsigned int pts; // 时间戳
		cv::Mat img;	  // 输入的该帧图片(roi之后)
		bool debug_mode;  // 是否debug模式
	};


	enum FOOD_REALTIME_SERVICE_PLATE_STATUS_TYPES
	{
		STATIC_EMPTY = 0, // 静止的空盘
		MOVING_EMPTY = 1, // 运动的空盘
		STATIC_FULL = 2,  // 静止的餐盘
		MOVING_FULL = 3,  // 运动的餐盘
		MOVING_2_STATIC = 4,  // 运动->静止
		STATIC_EMPTY_2_MOVING = 5,  // 静止空->运动
		STATIC_FULL_2_MOVING = 6,  // 静止餐->运动
	};


	struct DEBUG_INFO    //此部分为调试信息
	{
		cv::Mat back, fore, shadow;
		float movement_area;
		float match;
	};

	enum FOOD_OUTPUT_TYPES // 输出的类型
	{
		NORMAL = 0,   // 正常输出
		CHANGED = 1,  // 经过更改后的输出
	};

	struct FOOD_VIDEOPIPE_OUTPUT
	{
		int index;					// 图像索引,目前该字段无效
		bool has_best_obj;			// 是否具有目标,如果有则需要后续的AI识别
		unsigned int output_pts;	// 时间戳(与输入时的时间戳一致)
		cv::Mat best_img;			// 最佳的用于识别的图像帧
		bool debug_mode;			// 是否debug模式
		FOOD_OUTPUT_TYPES output_types;  // 输出的类型
		FOOD_REALTIME_SERVICE_PLATE_STATUS_TYPES service_plate_status;
		DEBUG_INFO debug_info;		// debug信息
		int error_code;			    // 错误码
	};

	class FoodVideoPipe
	{
		public:
			FoodVideoPipe();
			~FoodVideoPipe();

		public:
			//	目前该函数无效
			void SetROI(cv::Rect roi);
			//	设置标志物的图像
			void SetMarkMat(cv::Mat temp);
			//	返回标志物的图像
			cv::Mat GetMarkMat();

			// 设置标志物的阈值,这个阈值范围是0~1(建议0.95~0.99调调看);
			//          如果值设越大,越容易“把空盘当餐盘”回调出来,这样调用AI识别次数会变多。
			void SetMarkThreshold(float threshold);
			//	获取标志物的阈值
			float GetMarkThreshold();


			// 设置运动程度的阈值,这个阈值范围是0~1(建议0.1~0.2调调看);
			//           值设得越小,检测运动越灵敏
			void SetMovementThreshold(float threshold);
			float GetMovementThreshold();


			// 设置运动面积的阈值;
			//           值设得越小,检测运动越灵敏
			void SetAreaThreshold(float threshold);
			float GetAreaThreshold();

			//	开始追踪判断目标
			int Trace(FOOD_VIDEOPIPE_INPUT input);
			// 设置回调函数
			void SetResultCallback(VideoPipeCallback cb, void* user);


		private:
			void trace_out(FOOD_VIDEOPIPE_INPUT input);
			bool movement_detect(FOOD_VIDEOPIPE_INPUT input);
			bool mark_detect(FOOD_VIDEOPIPE_INPUT input);
			void resize(cv::Mat src, cv::Mat& dst, float scale);

		private:

			// roi
			cv::Rect roi_;

			// call back
			VideoPipeCallback cb_function_;
			void* cb_param_;

			// video track handle
			void* video_handle_;

	};

//*****************************************
//motion
//*****************************************
	struct MOTION_VIDEOPIPE_INPUT
	{
		unsigned int pts; // 时间戳
		cv::Mat img;	  // 输入的该帧图片(roi之后)
		std::vector<cv::Point> obj_points;
	};

	struct MOTION_VIDEOPIPE_OUTPUT
	{
		int index;					// 图像索引,目前该字段无效
		unsigned int output_pts;	// 时间戳(与输入时的时间戳一致)
		cv::Mat best_img;			// 最佳的用于识别的图像帧
		bool debug_mode;			// 是否debug模式
		int error_code;			    // 错误码
	};

	class MotionVideoPipe
	{
		public:
			MotionVideoPipe();
			~MotionVideoPipe();

		public:
			void SetROI(cv::Rect roi);

			//	喂数据
			int FeedFrame(MOTION_VIDEOPIPE_INPUT input);
			// 设置回调函数
			void SetResultCallback(VideoPipeCallback cb, void* user);


		private:
			void trace_out(MOTION_VIDEOPIPE_INPUT input);

		private:
			// roi
			cv::Rect roi_;

			// call back
			VideoPipeCallback cb_function_;
			void* cb_param_;

			// 
			void* video_handle_;

	};

//*****************************************
//depth
//*****************************************

	enum DEPTH_VIDEOPIPE_STATUS // 输出的类型
	{
		DEPTH_IN = 0,    // 进入
		DEPTH_OUT = 1,  // 出去
	};

	struct DEPTH_VIDEOPIPE_INPUT
	{
		unsigned int pts;			// 时间戳
		cv::Mat img;				// 输入的该帧图片(roi之后)
		bool debug_mode;			// 是否debug模式
	};

	struct DEPTH_VIDEOPIPE_OUTPUT
	{
		int index;					// 图像索引,目前该字段无效
		unsigned int output_pts;	// 时间戳(与输入时的时间戳一致)
		DEPTH_VIDEOPIPE_STATUS status; //状态
		cv::Mat best_img;			// 最佳的用于识别的图像帧
		bool debug_mode;			// 是否debug模式
		int error_code;			    // 错误码
	};

	class DepthVideoPipe
	{
	public:
		DepthVideoPipe();
		~DepthVideoPipe();

	public:
		void SetROI(cv::Rect roi);

		//	喂数据
		int FeedFrame(DEPTH_VIDEOPIPE_INPUT input);
		// 设置回调函数
		void SetResultCallback(VideoPipeCallback cb, void* user);

		// 设置运动程度的阈值,这个阈值范围是0~1(建议0.1~0.2调调看);
		//           值设得越小,检测运动越灵敏
		void SetAreaThreshold(float threshold);
		float GetAreaThreshold();

		// 设置有效深度信息检测范围,这个阈值范围;
		int SetVaildDepthRange(float* valid_depth_range);
		int GetVaildDepthRange(float* valid_depth_range);

	private:
		void trace_out(DEPTH_VIDEOPIPE_STATUS status);
		bool detect_obj(DEPTH_VIDEOPIPE_INPUT input);
	private:
		// roi
		cv::Rect roi_;

		// call back
		VideoPipeCallback cb_function_;
		void* cb_param_;

		// 
		void* video_handle_;

	};


}


#endif