Reputation: 36
I wanted to ask regarding groupRectangles function.
I am writing the following code in python -
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#defining the face
thresh=1
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
print faces
faces_1,weights=cv2.groupRectangles(faces, thresh)
where vec is the returning recl from the detectMultiscal step, 1 is the groupThreshold and eps is 0.2
But it is throwing me a runtime error while executing. I tried to run the code by using try-except but still it is throwing me the same error.
Runtime Error!
Program:C:\Python27\pythonw.exe
This application has requested the Runtime to terminate it in an unusual way.
It will be of great help if someone can provide some sample grouprectangle code in python, so that i can make my working code in the same format, as in the documentation of this code i am unable to find any examples.
Cheers!
Upvotes: 2
Views: 6748
Reputation: 26
If anyone is still looking issues regarding bounding box merge. Morphology is what you need to understand. Note: Don't use random color to produce random bounding box. Morphology technique fails unless you want to do it manually.
https://docs.opencv.org/3.4/db/df6/tutorial_erosion_dilatation.html
Upvotes: 0
Reputation: 1349
I had the same problem. I managed to make it not crash (but I don't know if the results are accurate) by casting to a "list":
cv2.groupRectangles(list(rectVec), thresh)
Upvotes: 3
Reputation: 6080
The documentation off the two functions is:
cv2.CascadeClassifier.detectMultiScale(image[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize]]]]]) → objects¶
cv2.groupRectangles(rectList, groupThreshold[, eps]) → rectList, weights
This suggests the following usage:
casc = cv2.CascadeClassifier(filename)
rectVec = casc.detectMultiScale(im)
thresh = 1
rectList, weights = cv2.groupRectangles(rectVec, thresh) # eps is optional
I just double checked that above code is working for me. Make sure that your OpenCV Version and Python bindings are up to date (my OpenCV Version is 2.4.6.1) and that all your inputs have the right format (classifier file, input image).
Upvotes: 0