简体   繁体   中英

how to use cv::Mat imgbuf created by pointer to video data

I am reading the raw video data from the read buffer using

cv::Mat imgbuf(Size(640, 480), CV_8UC3, &mem[0], (640*3));

This variable imgbuf I am passing to face detection algorithm which detects the face & draws the rectangle around the face. after that I am getting output something like

输出无需调整大小功能

I tried with below code where I am performing resize operation before pass to face detection algorithm. by using this method it is working fine. but without resizing function I am getting noticeable output with rectangle around the face.

输出与调整大小功能

 while(1)
 {
 unsigned char *mem = (unsigned char*)mmap(NULL, page_offset + len,
 PROT_READ |PROT_WRITE, MAP_PRIVATE, fd, page_base); 
 cv::Mat imgbuf(Size(640, 480), CV_8UC3, &mem[0], (640*3));

 cv::resize(imgbuf,imgbuf,(640,480)); //Dummy function to get the right output.


 auto result = v->facedetection(imgbuf);
    for (const auto &r : result.rects) {
 cv::rectangle(imgbuf,cv::Rect{ cv::Point(r.x * imgbuf.cols, r.y * 
 imgbuf.rows),cv::Size{(int)(r.width * imgbuf.cols), (int)(r.height * 
   imgbuf.rows) } },0xff);

   }
  imshow("face-detection", imgbuf);
  waitKey(1);

can anybody help be to sort out this problem

Test this method:

unsigned char *mem = (unsigned char*)mmap(NULL, page_offset + len,
 PROT_READ |PROT_WRITE, MAP_PRIVATE, fd, page_base); 

cv::Mat imgbuf(480,640, CV_8UC3, &mem[0]);
cv::Mat img_2, img_3;
cv::resize(imgbuf,img_2,cv::Size(640,480));
img_2.copyTo(img_3);
auto result = v->facedetection(img_2);

for (const auto &r : result.rects)
{
   cv::Rect myR = cv::Rect(r.x * img_2.cols, r.y * img_2.rows, (int)(r.width * img_2.cols), 
   (int)(r.height * img_2.rows));

   cv::rectangle(img_3,myR,Scalar(0, 0, 255), 1);
}
imshow("Result", img_3);
waitKey(0);

After getting a valid result you can optimize this and use less of "Mat"s.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM