save_snapshot_reprocessing.h 2.29 KB
/*
 * @Author: yangzilong
 * @Date: 2021-12-14 17:51:04
 * @Last Modified by: yangzilong
 * @Email: yangzilong@objecteye.com
 * @Description:
 */
#pragma once
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <string.h>
#include "base_reprocessing_unit.h"
#include <queue>
#include <mutex>

#ifdef POST_USE_RABBITMQ
#include "post_reprocessing.hpp"
#include <memory>
#endif // #ifdef POST_USE_RABBITMQ

using namespace std;
// using namespace std;
using std::string;
using std::queue;

#include <condition_variable>


struct SNAPSHOT_IMAGE_UNIT {
	cv::Mat image;
	cv::Mat ori_image;

	string file_name;
	string ori_file_name;
	OBJ_KEY obj_key;
	algorithm_type_t _algor;
	sy_rect obj_rect;

#ifdef POST_USE_RABBITMQ
	string json_str;
#endif
	SNAPSHOT_IMAGE_UNIT(int height, int width, int type, float* data) :image(height, width, type, data)  {}
	SNAPSHOT_IMAGE_UNIT(int height, int width, int type, unsigned char* data) :image(height, width, type, data) {}
	SNAPSHOT_IMAGE_UNIT(int height, int width, int type, unsigned char* data, int ori_height, int ori_width, int ori_type, unsigned char* ori_data,  algorithm_type_t algor)
	: image(height, width, type, data)
	, ori_image(ori_height, ori_width, ori_type, ori_data)
	, _algor(algor) {}

	SNAPSHOT_IMAGE_UNIT()
	: _algor(algorithm_type_t::UNKNOWN)
	{}
};

class save_snapshot_reprocessing : public base_reprocessing_unit
{
public:
	save_snapshot_reprocessing();
	void save_snapshot_reprocessing_release();

	void add_newtask(const string taskid);
	void delete_finishtask(const string taskid);

#ifdef POST_USE_RABBITMQ
	void set_callback(callback_t cb);
#endif


	void reprocessing_process(const OBJ_KEY &obj_key);
    void reprocessing_process_face(const OBJ_KEY &obj_key); //人脸快照后处理函数

	void reprocessing_process_wo_locus(const OBJ_KEY &obj_key, const multi_image_t &m_image, bool enable_async
#ifdef POST_USE_RABBITMQ
									   , const std::string &json_str
#endif
	);

public:
	queue<SNAPSHOT_IMAGE_UNIT> waitforsave_image_queue;
	mutable std::mutex waitforsave_image_queue_mutex;

	set<string> task_on_play;
	// map<OBJ_KEY, int> save_snapshot_info_count; // debug by zsh
	mutable std::mutex waitforchange_taskid_mutex;

#ifdef POST_USE_RABBITMQ
	callback_t callback_;
	std::shared_ptr<mq::post_rabbitmq_reprocessing> rbmq_handler_;
#endif
};