#include #include #include #include #ifdef _MSC_VER #include #endif #include "highgui.h" #include "cv.h" #include #include #include "left_over_det.h" #include #include "RegionAssist.h" using namespace std; using namespace cv; void test_left_over_det(); int main() { test_left_over_det(); system("pause"); } #include #include void test_left_over_det() { char imgpath[260]; CvCapture* video1 = cvCaptureFromFile("./video2.mp4"); // 用opencv函数读取视频的一帧 IplImage *src = cvQueryFrame(video1); void *tools = nullptr; rs_param param; param.frame_num = 100; param.rect_num = 2; param.max_obj_num = 10; param.process_width = src->width; param.process_height = src->height; param.min_area = 10; param.max_area = 10000; { int index = 0; param.rect[index].point_num = 5; param.rect[index].p_roi[0].x_ = 560; param.rect[index].p_roi[0].y_ = 0; param.rect[index].p_roi[1].x_ = 1425; param.rect[index].p_roi[1].y_ = 0; param.rect[index].p_roi[2].x_ = 1400; param.rect[index].p_roi[2].y_ = 260; param.rect[index].p_roi[3].x_ = 560; param.rect[index].p_roi[3].y_ = 290; param.rect[index].p_roi[4].x_ = 560; param.rect[index].p_roi[4].y_ = 0; index = 1; param.rect[index].point_num = 5; param.rect[index].p_roi[0].x_ = 550; param.rect[index].p_roi[0].y_ = 300; param.rect[index].p_roi[1].x_ = 1390; param.rect[index].p_roi[1].y_ = 260; param.rect[index].p_roi[2].x_ = 1390; param.rect[index].p_roi[2].y_ = 620; param.rect[index].p_roi[3].x_ = 580; param.rect[index].p_roi[3].y_ = 650; param.rect[index].p_roi[4].x_ = 550; param.rect[index].p_roi[4].y_ = 300; } #ifndef _MSC_VER strcpy(param.auth.url, "192.168.10.4"); param.auth.port = 8888; #endif param.type = PRODUCT_ID; if (rs_init(&tools, param) != 0) { cout << "hp_init ailed!" << endl; return; } else { printf("hp_init suceed!\n"); } //初始化背景图片 int init_bk_framecount = 0; while (src && init_bk_framecount < 1) { //src = cvQueryFrame(video1); //正常使用 可初始化诺干帧 直到取到没有人的干净的背景画面 cv::Mat back_image = cv::imread("base_rgb.jpg"); sy_img img; img.set_data(back_image.cols, back_image.rows, back_image.channels(), (unsigned char *)back_image.data); rs_init_background(tools, img); init_bk_framecount++; } while (src) { src = cvQueryFrame(video1); //auto frame = cvCloneImage(src); if (!src) break; sy_img syimg; syimg.set_data(src->width, src->height, src->nChannels, (unsigned char *)src->imageData); rs_result result{}; result.obj_infos = new ms_object_info[param.max_obj_num]{}; rs_process(tools, syimg, &result); ExternalRectangle((unsigned char*)(src->imageData), src->width, src->height, result.obj_infos, result.obj_count, src->widthStep, 1); std::string str; std::string alarm; for (int i = 0; i < result.obj_count; i++) { { if (result.obj_infos[i].pb_alarm_type) { switch (result.obj_infos[i].pb_alarm_type) { case 1: printf("obj %d: 进入禁区\n", result.obj_infos[i].unique_id); str = " 有目标闯入禁区 "; break; case 2: printf("obj %d: 离开禁区\n", result.obj_infos[i].unique_id); str = " 有目标离开禁区 "; break; case 3: printf("obj %d: 单向越界\n", result.obj_infos[i].unique_id); str = " 有目标单向越界 "; break; case 4: printf("obj %d: 双向越界\n", result.obj_infos[i].unique_id); str = " 有目标越界 "; break; case 5: printf("obj %d: 徘徊\n", result.obj_infos[i].unique_id); str = " 有目标在禁区内徘徊 "; break; case 6: printf("obj %d: 丢包\n", result.obj_infos[i].unique_id); str = " 丢包 "; break; default: break; } } else { ; } } } delete[] result.obj_infos; //cvWriteFrame(writer, srcscale); // 图像显示 cvShowImage("1channels", src); //cvReleaseImage(&frame); cvWaitKey(1); //break; } rs_release(&tools); cvReleaseImage(&src); cvReleaseCapture(&video1); }