c++ - OpenCV face deteciton returns too many faces -


i have little problem. trying make face detection via kinect v1.i data kinect , convert opencv mat. trying detect faces in image function return face.size() = cca 250000000. know problem ?

void getkinectdata(glubyte* dest) {     nui_image_frame imageframe; //structure of frame ( number,res etc )     nui_locked_rect lockedrect; //pointer actual data     if (sensor->nuiimagestreamgetnextframe(rgbstream, 0, &imageframe) < 0) return;     inuiframetexture* texture = imageframe.pframetexture; // manages frame data     texture->lockrect(0, &lockedrect, null, 0);     iplimage* image = cvcreateimageheader(cvsize(color_width, color_hight), ipl_depth_8u, 4);     if (lockedrect.pitch != 0) // pitch - how many bytes in each row of frame     {         byte* curr = (byte*)lockedrect.pbits;         cvsetdata(image, curr, lockedrect.pitch);         const byte* dataend = curr + (widthx*heightx) * 4;         while (curr < dataend) {             *dest++ = *curr++;         }     }     //cvshowimage("color image", image);     m = cv::cvarrtomat(image).clone();     detectanddisplay(m);      texture->unlockrect(0);     sensor->nuiimagestreamreleaseframe(rgbstream, &imageframe);  }  void detectanddisplay(cv::mat frame) { std::vector<cv::rect> faces;      cv::mat frame_gray;      cvtcolor(frame, frame_gray, cv::color_bgr2gray);     equalizehist(frame_gray, frame_gray);     //-- detect faces     face_cascade.detectmultiscale(frame_gray, faces, 1.1, 2, 0 | cv_haar_scale_image, cv::size(24, 24));      (size_t = 0; < faces.size(); i++)     {         cv::point center(faces[i].x + faces[i].width / 2, faces[i].y + faces[i].height / 2);         ellipse(frame, center, cv::size(faces[i].width / 2, faces[i].height / 2), 0, 0, 360, cv::scalar(255, 0, 255), 4, 8, 0);          cv::mat faceroi = frame_gray(faces[i]);         std::vector<cv::rect> eyes;         /*         //-- in each face, detect eyes         eyes_cascade.detectmultiscale(faceroi, eyes, 1.1, 2, 0 | cascade_scale_image, size(30, 30));          (size_t j = 0; j < eyes.size(); j++)         {             point eye_center(faces[i].x + eyes[j].x + eyes[j].width / 2, faces[i].y + eyes[j].y + eyes[j].height / 2);             int radius = cvround((eyes[j].width + eyes[j].height)*0.25);             circle(frame, eye_center, radius, scalar(255, 0, 0), 4, 8, 0);         }*/     }     //-- show got     imshow(window_name, frame); } 

i know old, had similar problem, thought others may benefit.

linking release opencv_objdetect library during debug build lead detectmultiscale() returning enormous vector containing hundreds of thousands of erroneous rectangles. here's how fix in visual studio 2017 (i'm using opencv version 3.2, adjust names of libraries mentioned correspond version using):

  1. project | (your project name) properties... (or right click on project in solution explorer & select properties)
  2. change configuration debug , platform all platforms (or can repeat these steps individually each debug platform)
  3. go linker | input , make sure opencv_objdetect320d.lib in addition dependencies list , remove opencv_objdetect320.lib if it's there.
  4. repeat above steps configuration == release, time make sure linker | input includes opencv_objdetect320.lib (no trailing d in name) in addition dependencies list , remove opencv_objdetect320d.lib if it's there.

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -