164 lines
4.9 KiB
C++
164 lines
4.9 KiB
C++
/*
|
|
* @Date: 2024-09-04 18:57:40
|
|
* @LastEditors: Jacky
|
|
* @LastEditTime: 2024-09-20 17:57:50
|
|
* @FilePath: /GeneralTracker/Universal/CModuleOsd.cpp
|
|
*/
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include "CModuleOsd.h"
|
|
#include "InterfaceMpp.h"
|
|
#include "Fps.hpp"
|
|
#include "MemoryManage.h"
|
|
|
|
int CModuleOsd::create(const char* name){
|
|
m_pcName = std::string(name);
|
|
m_pSelfQueue.queueInit(m_pcName, QUEUE_SIZE);
|
|
return 0;
|
|
}
|
|
|
|
int CModuleOsd::destroy(){
|
|
stop();
|
|
return 0;
|
|
}
|
|
|
|
int CModuleOsd::set_data(const char* data, void* value){
|
|
return 0;
|
|
}
|
|
|
|
char* CModuleOsd::get_data(){
|
|
return nullptr;
|
|
}
|
|
|
|
int CModuleOsd::start(const char* data){
|
|
if(_vi_thread){
|
|
return -1;
|
|
}
|
|
|
|
_thread_flag = true;
|
|
_vi_thread = new std::thread(std::bind(&CModuleOsd::moduleThread, std::ref(*this)));
|
|
return 0;
|
|
}
|
|
int CModuleOsd::stop(){
|
|
if(_vi_thread){
|
|
_thread_flag = false;
|
|
_vi_thread->join();
|
|
delete _vi_thread;
|
|
_vi_thread = nullptr;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void CModuleOsd::push_data(DataProcessBase *src, pool::IMemoryBlock* block){
|
|
m_pSelfQueue.sendFrame(block);
|
|
}
|
|
|
|
int CModuleOsd::moduleThread(){
|
|
int timeout = 100;
|
|
/* for osd EX. */
|
|
int timeref = 0;
|
|
char str[128];
|
|
GD_POINT start[5], end[5], text;
|
|
text.x = 100;
|
|
text.y = 100;
|
|
GD_RECT rect[5];
|
|
for(int i = 0; i < 5; i++) {
|
|
start[i].x = 100 + 50 * i;
|
|
start[i].y = 100 + 50 * i;
|
|
end[i].x = 100 + 50 * i;
|
|
end[i].y = 500 + 50 * i;
|
|
rect[i].x = 100 + 50 * i;
|
|
rect[i].y = 500 + 50 * i;
|
|
rect[i].w = 100;
|
|
rect[i].h = 100;
|
|
}
|
|
while(_thread_flag){
|
|
pool::IMemoryBlock* mb = m_pSelfQueue.getFrame(timeout);
|
|
if(mb){
|
|
AdditionalImp* imp = mb->data();
|
|
GD_VIDEO_FRAME_S *frame = mb->yuv();
|
|
TrackObject *track = imp->data<TrackObject*>(TRACK_OBJECT_NAME);
|
|
|
|
if (timeref == frame->u32FrameCnt) {
|
|
frame->u32FrameCnt = timeref + 2;
|
|
}
|
|
//输出接口
|
|
|
|
if(track->trackOutput.nStatus == 3){
|
|
GD_RECT rect;
|
|
rect.x = track->trackOutput.stTrackers->nX - track->trackOutput.stTrackers[0].nObjW / 2;
|
|
rect.y = track->trackOutput.stTrackers->nY - track->trackOutput.stTrackers[0].nObjH / 2;
|
|
rect.w = track->trackOutput.stTrackers[0].nObjW;
|
|
rect.h = track->trackOutput.stTrackers[0].nObjH;
|
|
rect.x = (rect.x <= 0 ? 0 : rect.x);
|
|
rect.y = (rect.y <= 0 ? 0 : rect.y);
|
|
mpp_image_draw_rects(frame, 2, 0x0AFF00FF, 1, &rect);
|
|
}
|
|
#if 0
|
|
memset(str, 0x00, 128);
|
|
snprintf(str, 127, "This is BM Frame. %d %d Format: %d Frame Count: %d ", frame->u32Width, frame->u32Height, frame->enPixelFormat, frame->u32FrameCnt);
|
|
|
|
mpp_image_draw_text(frame, str, 24, 0x0AFF0000, &text);
|
|
|
|
mpp_image_draw_rects(frame, 2, 0x0AFF00FF, 5, rect);
|
|
|
|
mpp_image_draw_lines(frame, 4, 0x0AFFAA00, 5, start, end);
|
|
|
|
#endif
|
|
if (0 == access("/tmp/debug_resize0", F_OK)){
|
|
GD_RECT resize_rect;
|
|
resize_rect.x = 540;
|
|
resize_rect.y = 412;
|
|
resize_rect.w = 200;
|
|
resize_rect.h = 200;
|
|
mpp_image_resize(frame, frame, &resize_rect, 3);
|
|
}
|
|
if (0 == access("/tmp/debug_resize1", F_OK)){
|
|
GD_RECT resize_rect;
|
|
resize_rect.x = 0;
|
|
resize_rect.y = 0;
|
|
resize_rect.w = 300;
|
|
resize_rect.h = 300;
|
|
mpp_image_resize(frame, frame, &resize_rect, 0);
|
|
}
|
|
if (0 == access("/tmp/debug_resize2", F_OK)){
|
|
mpp_image_resize(frame, frame, NULL, 3);
|
|
}
|
|
if (0 == access("/tmp/debug_pip", F_OK)){
|
|
GD_RECT src_rect;
|
|
src_rect.x = 540;
|
|
src_rect.y = 412;
|
|
src_rect.w = 200;
|
|
src_rect.h = 200;
|
|
|
|
GD_RECT dst_rect;
|
|
dst_rect.x = 800;
|
|
dst_rect.y = 650;
|
|
dst_rect.w = 300;
|
|
dst_rect.h = 300;
|
|
mpp_image_pip(frame, frame, &src_rect, &dst_rect);
|
|
}
|
|
|
|
if (0 == access("/tmp/dump_rgb", F_OK)){
|
|
GD_VIDEO_FRAME_S *rgb_frame = mb->rgb();
|
|
mpp_image_yuv2bgr(frame, rgb_frame);
|
|
std::ofstream fd;
|
|
const char* file = "./dump_rgb.data";
|
|
fd.open(file, std::ios::out | std::ios::binary);
|
|
fd.write((char*)rgb_frame->u64VirAddr[0], rgb_frame->u32Stride[0] * rgb_frame->u32Height);
|
|
fd.flush();
|
|
fd.close();
|
|
system("rm -f /tmp/dump_rgb");
|
|
}
|
|
|
|
mpp_image_free_private(frame);
|
|
|
|
timeref = frame->u32FrameCnt;
|
|
push_input_pipe(mb);
|
|
m_pSelfQueue.releaseFrame(mb);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|