简体   繁体   中英

opencv python detectMultiScale api

I was following this particular tutorial on object detection. He uses this version of detectMultiSacle function in his code, which allows him to adjust threshold for detection or something like that with rejectLevels and levelWeights:

Python:

cv2.CascadeClassifier.detectMultiScale(image,
rejectLevels, levelWeights[,
scaleFactor[, minNeighbors[, flags[,
minSize[, maxSize[,
outputRejectLevels]]]]]]) → objects

This is my code:

detectMultiScale(image=gray,
rejectLevels=rejectlevels,
levelWeights=levelweights)

But it gives the following error, which makes me confused:

 TypeError: 'rejectLevels' is an invalid keyword argument for this function

I was trying to use detectMultiScale(image, rejectLevels, levelWeights, scaleFactor) originally, but it gives me error that says the fourth argument can't be float, which made suspect I wasn't using the function I thought I was using.

I use pip to install opencv-python which is version 3.3.0.9. I couldn't find any python documents other than this webpage .

Appreciate some help. Like where can I find documents for latest python api, or some experience with this particular function.

It's pretty hard to find python documentation for OpenCV 3.3 but the OpenCV3.0 docs show that detectMultiScale uses ouputRejectLevels . Try using that argument.

Here's their breakdown:

Python: cv2.CascadeClassifier.detectMultiScale(image[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize]]]]]) → objects

Python: cv2.CascadeClassifier.detectMultiScale2(image[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize]]]]]) → objects, numDetections

Python: cv2.CascadeClassifier.detectMultiScale3(image[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize[, outputRejectLevels]]]]]]) → objects, rejectLevels, levelWeights

While the online documentation for the recent versions of OpenCV does not list information about the Python bindings, it is quite simple to find it -- it's embedded right in the Python module. At the least you will get the signatures of the methods in question.

Use the build-in help() function to access it.

For example (not that this is OpenCV 3.1, so double check it locally):

>>> import cv2
>>> c = cv2.CascadeClassifier()
>>> help(c.detectMultiScale)
Help on built-in function detectMultiScale:

detectMultiScale(...)
    detectMultiScale(image[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize]]]]]) -> objects

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