Ask Your Question
1

open CV detect multiscal issue

asked 2016-12-13 03:56:01 -0500

mohmed7258 gravatar image

Dears, im working with the object detection functions, exactly with the detect multiscal , and my problem that in some times "detectMultiScale" function detect objects(in my case faces) and when i try to get the ROI of that face, open CV throw an exception as follow:

terminate called after throwing an instance of 'cv::Exception' what(): /home/mohammad/yabrodi/opencv/opencv-3.0.0-alpha/modules/core/src/matrix.cpp:492: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function Mat

After investigation i found that "detectMultiScale" return an object of size greater than the original image used in the detection process. an exact case occurs as follow :

face_cascade.detectMultiScale(frame , faces_in_frame, 1.3, 2, 0| CASCADE_SCALE_IMAGE, Size(25, 25) ); frame.size().width = 720
frame.size().height = 565

faces_in_frame[0].x = 30
faces_in_frame[0].y = 137
faces_in_frame[0].width = 430
faces_in_frame[0].height = 430

and when i tried to get the ROI i got the exception above which is true since the height of the object is (137+ 430 = 567) which is grater than the frame height (565).

SO, what is the issue that let "detectMultiScale" return object with invalid size ???

my OpenCV version 3.1

thanks

edit retag flag offensive close merge delete

Comments

could you post your code ? . i thing there is a bug on your code. it seems you are using "opencv-3.0.0-alpha"

sturkmen gravatar imagesturkmen ( 2016-12-15 08:06:16 -0500 )edit

@sturkmen , yes you are right, im using opencv-3.0.0-alpha,, i thought it was 3.1 but apparently it was mistake. So opencv-3.0.0-alpha might produce such kind of issue??

mohmed7258 gravatar imagemohmed7258 ( 2016-12-15 08:23:57 -0500 )edit

as i remember i fixed a problem like yours in this PR. are you meet this problem with smiledetect.cpp?

sturkmen gravatar imagesturkmen ( 2016-12-15 08:57:04 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-12-15 07:13:33 -0500

pi-null-mezon gravatar image

Hey! You can simply crop all returned rectangles:

detectMultiscale(frame, faces_in_frame, ...)
cv::Rect _framerect = cv::Rect(0,0,frame.cols,frame.rows); 
for(size_t i = 0; i < faces_in_frame.size(); i++) {
    faces_in_frame[i] = faces_in_frame[i] & _framerect;
}
edit flag offensive delete link more

Comments

Thanks pi-null-mezon, this is what Im already did to continue my work,, thanks..

mohmed7258 gravatar imagemohmed7258 ( 2016-12-15 08:21:56 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-12-13 03:53:43 -0500

Seen: 203 times

Last updated: Dec 15 '16