OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 24 Oct 2019 09:44:27 -0500python facedetection detectMultiScalehttp://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/The function `cv2.detectMultiScale` can successfully detect the position of face and by using the fuction `cv2.detectMultiScale3` i can also know the confidence score of each detected face.
My question is the fuction `cv2.detectMultiScale3` only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window.
in this program i simply cut 1 image to several parts(using the `cv2.ROI`)
import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
and i get
> weight of 1 is () () () weight of 2
> is () () () weight of 3 is () () ()
> weight of 4 is () () () weight of 5
> is () () () weight of 6 is () () ()
> weight of 7 is () () () weight of 8
> is () () () weight of 9 is () () ()
> weight of 10 is () () () weight of 11
> is () () () weight of 12 is () () ()
> weight of 13 is () () () weight of 14
> is () () () weight of 15 is () () ()
> weight of 16 is () () () weight of 17
> is () () () weight of 18 is () () ()
> weight of 19 is () () () weight of 20
> is () () () weight of 21 is () () ()
> weight of 22 is () () () weight of 23
> is () () () weight of 24 is () () ()
> weight of 25 is () () () weight of 26
> is () () () weight of 27 is () () ()
> weight of 28 is () () () weight of 29
> is () () () weight of 30 is () () ()
> weight of 31 is () () () weight of 32
> is () () () weight of 33 is () () ()
> weight of 34 is () () () weight of 35
> is () () () weight of 36 is () () ()
> weight of 37 is () () () weight of 38
> is () () () weight of 39 is () () ()
> weight of 40 is () () () weight of 41
> is () () () weight of 42 is () () ()
> weight of 43 is () () () weight of 44
> is () () () weight of 45 is () () ()
> weight of 46 is [[ 4 10 37 37]]
> [[25]] [[ 7.2749402]] weight of 47 is
> () () () weight of 48 is [[ 0 13 32
> 32]] [[25]] [[ 8.64948004]]Mon, 04 Dec 2017 08:38:14 -0600http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/Comment by supra56 for <p>The function <code>cv2.detectMultiScale</code> can successfully detect the position of face and by using the fuction <code>cv2.detectMultiScale3</code> i can also know the confidence score of each detected face.</p>
<p>My question is the fuction <code>cv2.detectMultiScale3</code> only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window. </p>
<p>in this program i simply cut 1 image to several parts(using the <code>cv2.ROI</code>)</p>
<pre><code>import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
</code></pre>
<p>and i get</p>
<blockquote>
<p>weight of 1 is () () () weight of 2
is () () () weight of 3 is () () ()
weight of 4 is () () () weight of 5
is () () () weight of 6 is () () ()
weight of 7 is () () () weight of 8
is () () () weight of 9 is () () ()
weight of 10 is () () () weight of 11
is () () () weight of 12 is () () ()
weight of 13 is () () () weight of 14
is () () () weight of 15 is () () ()
weight of 16 is () () () weight of 17
is () () () weight of 18 is () () ()
weight of 19 is () () () weight of 20
is () () () weight of 21 is () () ()
weight of 22 is () () () weight of 23
is () () () weight of 24 is () () ()
weight of 25 is () () () weight of 26
is () () () weight of 27 is () () ()
weight of 28 is () () () weight of 29
is () () () weight of 30 is () () ()
weight of 31 is () () () weight of 32
is () () () weight of 33 is () () ()
weight of 34 is () () () weight of 35
is () () () weight of 36 is () () ()
weight of 37 is () () () weight of 38
is () () () weight of 39 is () () ()
weight of 40 is () () () weight of 41
is () () () weight of 42 is () () ()
weight of 43 is () () () weight of 44
is () () () weight of 45 is () () ()
weight of 46 is [[ 4 10 37 37]]
[[25]] [[ 7.2749402]] weight of 47 is
() () () weight of 48 is [[ 0 13 32
32]] [[25]] [[ 8.64948004]]</p>
</blockquote>
http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179948#post-id-179948@StevenPuttemans. If I'm wrong, I will withdrawn my commentThu, 07 Dec 2017 05:47:49 -0600http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179948#post-id-179948Comment by StevenPuttemans for <p>The function <code>cv2.detectMultiScale</code> can successfully detect the position of face and by using the fuction <code>cv2.detectMultiScale3</code> i can also know the confidence score of each detected face.</p>
<p>My question is the fuction <code>cv2.detectMultiScale3</code> only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window. </p>
<p>in this program i simply cut 1 image to several parts(using the <code>cv2.ROI</code>)</p>
<pre><code>import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
</code></pre>
<p>and i get</p>
<blockquote>
<p>weight of 1 is () () () weight of 2
is () () () weight of 3 is () () ()
weight of 4 is () () () weight of 5
is () () () weight of 6 is () () ()
weight of 7 is () () () weight of 8
is () () () weight of 9 is () () ()
weight of 10 is () () () weight of 11
is () () () weight of 12 is () () ()
weight of 13 is () () () weight of 14
is () () () weight of 15 is () () ()
weight of 16 is () () () weight of 17
is () () () weight of 18 is () () ()
weight of 19 is () () () weight of 20
is () () () weight of 21 is () () ()
weight of 22 is () () () weight of 23
is () () () weight of 24 is () () ()
weight of 25 is () () () weight of 26
is () () () weight of 27 is () () ()
weight of 28 is () () () weight of 29
is () () () weight of 30 is () () ()
weight of 31 is () () () weight of 32
is () () () weight of 33 is () () ()
weight of 34 is () () () weight of 35
is () () () weight of 36 is () () ()
weight of 37 is () () () weight of 38
is () () () weight of 39 is () () ()
weight of 40 is () () () weight of 41
is () () () weight of 42 is () () ()
weight of 43 is () () () weight of 44
is () () () weight of 45 is () () ()
weight of 46 is [[ 4 10 37 37]]
[[25]] [[ 7.2749402]] weight of 47 is
() () () weight of 48 is [[ 0 13 32
32]] [[25]] [[ 8.64948004]]</p>
</blockquote>
http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179890#post-id-179890@eshirima you are correct in the fact that @supra56 is just plain wrongWed, 06 Dec 2017 12:20:44 -0600http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179890#post-id-179890Comment by eshirima for <p>The function <code>cv2.detectMultiScale</code> can successfully detect the position of face and by using the fuction <code>cv2.detectMultiScale3</code> i can also know the confidence score of each detected face.</p>
<p>My question is the fuction <code>cv2.detectMultiScale3</code> only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window. </p>
<p>in this program i simply cut 1 image to several parts(using the <code>cv2.ROI</code>)</p>
<pre><code>import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
</code></pre>
<p>and i get</p>
<blockquote>
<p>weight of 1 is () () () weight of 2
is () () () weight of 3 is () () ()
weight of 4 is () () () weight of 5
is () () () weight of 6 is () () ()
weight of 7 is () () () weight of 8
is () () () weight of 9 is () () ()
weight of 10 is () () () weight of 11
is () () () weight of 12 is () () ()
weight of 13 is () () () weight of 14
is () () () weight of 15 is () () ()
weight of 16 is () () () weight of 17
is () () () weight of 18 is () () ()
weight of 19 is () () () weight of 20
is () () () weight of 21 is () () ()
weight of 22 is () () () weight of 23
is () () () weight of 24 is () () ()
weight of 25 is () () () weight of 26
is () () () weight of 27 is () () ()
weight of 28 is () () () weight of 29
is () () () weight of 30 is () () ()
weight of 31 is () () () weight of 32
is () () () weight of 33 is () () ()
weight of 34 is () () () weight of 35
is () () () weight of 36 is () () ()
weight of 37 is () () () weight of 38
is () () () weight of 39 is () () ()
weight of 40 is () () () weight of 41
is () () () weight of 42 is () () ()
weight of 43 is () () () weight of 44
is () () () weight of 45 is () () ()
weight of 46 is [[ 4 10 37 37]]
[[25]] [[ 7.2749402]] weight of 47 is
() () () weight of 48 is [[ 0 13 32
32]] [[25]] [[ 8.64948004]]</p>
</blockquote>
http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179872#post-id-179872@supra56 Pardon my ignorance but I still do not understand where you are going with this. How does OP getting that output having anything to do with him/her not putting `imread`,`cvtColor` and `detectMultiScale` in a *for* loop?Wed, 06 Dec 2017 08:49:46 -0600http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179872#post-id-179872Comment by supra56 for <p>The function <code>cv2.detectMultiScale</code> can successfully detect the position of face and by using the fuction <code>cv2.detectMultiScale3</code> i can also know the confidence score of each detected face.</p>
<p>My question is the fuction <code>cv2.detectMultiScale3</code> only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window. </p>
<p>in this program i simply cut 1 image to several parts(using the <code>cv2.ROI</code>)</p>
<pre><code>import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
</code></pre>
<p>and i get</p>
<blockquote>
<p>weight of 1 is () () () weight of 2
is () () () weight of 3 is () () ()
weight of 4 is () () () weight of 5
is () () () weight of 6 is () () ()
weight of 7 is () () () weight of 8
is () () () weight of 9 is () () ()
weight of 10 is () () () weight of 11
is () () () weight of 12 is () () ()
weight of 13 is () () () weight of 14
is () () () weight of 15 is () () ()
weight of 16 is () () () weight of 17
is () () () weight of 18 is () () ()
weight of 19 is () () () weight of 20
is () () () weight of 21 is () () ()
weight of 22 is () () () weight of 23
is () () () weight of 24 is () () ()
weight of 25 is () () () weight of 26
is () () () weight of 27 is () () ()
weight of 28 is () () () weight of 29
is () () () weight of 30 is () () ()
weight of 31 is () () () weight of 32
is () () () weight of 33 is () () ()
weight of 34 is () () () weight of 35
is () () () weight of 36 is () () ()
weight of 37 is () () () weight of 38
is () () () weight of 39 is () () ()
weight of 40 is () () () weight of 41
is () () () weight of 42 is () () ()
weight of 43 is () () () weight of 44
is () () () weight of 45 is () () ()
weight of 46 is [[ 4 10 37 37]]
[[25]] [[ 7.2749402]] weight of 47 is
() () () weight of 48 is [[ 0 13 32
32]] [[25]] [[ 8.64948004]]</p>
</blockquote>
http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179864#post-id-179864@eshirima: This is what he/she getting this......weight of 1 is () () () weight of 2 is () () () weight of 3 is () () () weight of 4 is () () () weight of 5 is () () () weight of 6 is () () () weight of 7 is () () () weight of 8 is () () () weight of 9 is () () ()Wed, 06 Dec 2017 07:27:04 -0600http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179864#post-id-179864Comment by StevenPuttemans for <p>The function <code>cv2.detectMultiScale</code> can successfully detect the position of face and by using the fuction <code>cv2.detectMultiScale3</code> i can also know the confidence score of each detected face.</p>
<p>My question is the fuction <code>cv2.detectMultiScale3</code> only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window. </p>
<p>in this program i simply cut 1 image to several parts(using the <code>cv2.ROI</code>)</p>
<pre><code>import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
</code></pre>
<p>and i get</p>
<blockquote>
<p>weight of 1 is () () () weight of 2
is () () () weight of 3 is () () ()
weight of 4 is () () () weight of 5
is () () () weight of 6 is () () ()
weight of 7 is () () () weight of 8
is () () () weight of 9 is () () ()
weight of 10 is () () () weight of 11
is () () () weight of 12 is () () ()
weight of 13 is () () () weight of 14
is () () () weight of 15 is () () ()
weight of 16 is () () () weight of 17
is () () () weight of 18 is () () ()
weight of 19 is () () () weight of 20
is () () () weight of 21 is () () ()
weight of 22 is () () () weight of 23
is () () () weight of 24 is () () ()
weight of 25 is () () () weight of 26
is () () () weight of 27 is () () ()
weight of 28 is () () () weight of 29
is () () () weight of 30 is () () ()
weight of 31 is () () () weight of 32
is () () () weight of 33 is () () ()
weight of 34 is () () () weight of 35
is () () () weight of 36 is () () ()
weight of 37 is () () () weight of 38
is () () () weight of 39 is () () ()
weight of 40 is () () () weight of 41
is () () () weight of 42 is () () ()
weight of 43 is () () () weight of 44
is () () () weight of 45 is () () ()
weight of 46 is [[ 4 10 37 37]]
[[25]] [[ 7.2749402]] weight of 47 is
() () () weight of 48 is [[ 0 13 32
32]] [[25]] [[ 8.64948004]]</p>
</blockquote>
http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179860#post-id-179860the code only stores weights if you succeed in passing the window throughout the complete cascade. If not it leaves it initialized. So if you want this behaviour, you will have to break open the existing code and find a case specific solution.... if you do attempt this, keep me posted, since i am interested in this behaviour as well.Wed, 06 Dec 2017 04:43:12 -0600http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179860#post-id-179860Comment by eshirima for <p>The function <code>cv2.detectMultiScale</code> can successfully detect the position of face and by using the fuction <code>cv2.detectMultiScale3</code> i can also know the confidence score of each detected face.</p>
<p>My question is the fuction <code>cv2.detectMultiScale3</code> only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window. </p>
<p>in this program i simply cut 1 image to several parts(using the <code>cv2.ROI</code>)</p>
<pre><code>import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
</code></pre>
<p>and i get</p>
<blockquote>
<p>weight of 1 is () () () weight of 2
is () () () weight of 3 is () () ()
weight of 4 is () () () weight of 5
is () () () weight of 6 is () () ()
weight of 7 is () () () weight of 8
is () () () weight of 9 is () () ()
weight of 10 is () () () weight of 11
is () () () weight of 12 is () () ()
weight of 13 is () () () weight of 14
is () () () weight of 15 is () () ()
weight of 16 is () () () weight of 17
is () () () weight of 18 is () () ()
weight of 19 is () () () weight of 20
is () () () weight of 21 is () () ()
weight of 22 is () () () weight of 23
is () () () weight of 24 is () () ()
weight of 25 is () () () weight of 26
is () () () weight of 27 is () () ()
weight of 28 is () () () weight of 29
is () () () weight of 30 is () () ()
weight of 31 is () () () weight of 32
is () () () weight of 33 is () () ()
weight of 34 is () () () weight of 35
is () () () weight of 36 is () () ()
weight of 37 is () () () weight of 38
is () () () weight of 39 is () () ()
weight of 40 is () () () weight of 41
is () () () weight of 42 is () () ()
weight of 43 is () () () weight of 44
is () () () weight of 45 is () () ()
weight of 46 is [[ 4 10 37 37]]
[[25]] [[ 7.2749402]] weight of 47 is
() () () weight of 48 is [[ 0 13 32
32]] [[25]] [[ 8.64948004]]</p>
</blockquote>
http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179812#post-id-179812@supra56 Why exactly can't he/she put `imread`, `cvtColor` and `detectMultiScale` in a *for* loop? I have done this multiple times with no problems whatsoever.Tue, 05 Dec 2017 14:29:30 -0600http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179812#post-id-179812Comment by supra56 for <p>The function <code>cv2.detectMultiScale</code> can successfully detect the position of face and by using the fuction <code>cv2.detectMultiScale3</code> i can also know the confidence score of each detected face.</p>
<p>My question is the fuction <code>cv2.detectMultiScale3</code> only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window. </p>
<p>in this program i simply cut 1 image to several parts(using the <code>cv2.ROI</code>)</p>
<pre><code>import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
</code></pre>
<p>and i get</p>
<blockquote>
<p>weight of 1 is () () () weight of 2
is () () () weight of 3 is () () ()
weight of 4 is () () () weight of 5
is () () () weight of 6 is () () ()
weight of 7 is () () () weight of 8
is () () () weight of 9 is () () ()
weight of 10 is () () () weight of 11
is () () () weight of 12 is () () ()
weight of 13 is () () () weight of 14
is () () () weight of 15 is () () ()
weight of 16 is () () () weight of 17
is () () () weight of 18 is () () ()
weight of 19 is () () () weight of 20
is () () () weight of 21 is () () ()
weight of 22 is () () () weight of 23
is () () () weight of 24 is () () ()
weight of 25 is () () () weight of 26
is () () () weight of 27 is () () ()
weight of 28 is () () () weight of 29
is () () () weight of 30 is () () ()
weight of 31 is () () () weight of 32
is () () () weight of 33 is () () ()
weight of 34 is () () () weight of 35
is () () () weight of 36 is () () ()
weight of 37 is () () () weight of 38
is () () () weight of 39 is () () ()
weight of 40 is () () () weight of 41
is () () () weight of 42 is () () ()
weight of 43 is () () () weight of 44
is () () () weight of 45 is () () ()
weight of 46 is [[ 4 10 37 37]]
[[25]] [[ 7.2749402]] weight of 47 is
() () () weight of 48 is [[ 0 13 32
32]] [[25]] [[ 8.64948004]]</p>
</blockquote>
http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179715#post-id-179715As above code.. This is not the right way. You can't put inside `for` looping block condition **imread**, **cvColor** and **detectMultiScale3**. I haven't attempted `detectMultiScale3` yet.Mon, 04 Dec 2017 13:00:00 -0600http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179715#post-id-179715Comment by supra56 for <p>The function <code>cv2.detectMultiScale</code> can successfully detect the position of face and by using the fuction <code>cv2.detectMultiScale3</code> i can also know the confidence score of each detected face.</p>
<p>My question is the fuction <code>cv2.detectMultiScale3</code> only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window. </p>
<p>in this program i simply cut 1 image to several parts(using the <code>cv2.ROI</code>)</p>
<pre><code>import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
</code></pre>
<p>and i get</p>
<blockquote>
<p>weight of 1 is () () () weight of 2
is () () () weight of 3 is () () ()
weight of 4 is () () () weight of 5
is () () () weight of 6 is () () ()
weight of 7 is () () () weight of 8
is () () () weight of 9 is () () ()
weight of 10 is () () () weight of 11
is () () () weight of 12 is () () ()
weight of 13 is () () () weight of 14
is () () () weight of 15 is () () ()
weight of 16 is () () () weight of 17
is () () () weight of 18 is () () ()
weight of 19 is () () () weight of 20
is () () () weight of 21 is () () ()
weight of 22 is () () () weight of 23
is () () () weight of 24 is () () ()
weight of 25 is () () () weight of 26
is () () () weight of 27 is () () ()
weight of 28 is () () () weight of 29
is () () () weight of 30 is () () ()
weight of 31 is () () () weight of 32
is () () () weight of 33 is () () ()
weight of 34 is () () () weight of 35
is () () () weight of 36 is () () ()
weight of 37 is () () () weight of 38
is () () () weight of 39 is () () ()
weight of 40 is () () () weight of 41
is () () () weight of 42 is () () ()
weight of 43 is () () () weight of 44
is () () () weight of 45 is () () ()
weight of 46 is [[ 4 10 37 37]]
[[25]] [[ 7.2749402]] weight of 47 is
() () () weight of 48 is [[ 0 13 32
32]] [[25]] [[ 8.64948004]]</p>
</blockquote>
http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179714#post-id-179714I will rephrase code for you.
import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail))
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %dMon, 04 Dec 2017 12:54:48 -0600http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?comment=179714#post-id-179714Answer by supra56 for <p>The function <code>cv2.detectMultiScale</code> can successfully detect the position of face and by using the fuction <code>cv2.detectMultiScale3</code> i can also know the confidence score of each detected face.</p>
<p>My question is the fuction <code>cv2.detectMultiScale3</code> only tells confidence scores of the search windows of detected faces,and my thought is when i slowly move the search window,it can tell me the socres for every window(even if they are very small) but not only the detected faces window. </p>
<p>in this program i simply cut 1 image to several parts(using the <code>cv2.ROI</code>)</p>
<pre><code>import os
import cv2
from PIL import Image,ImageDraw
image_save_path_head = "H:/OpenCV-demo-master/FaceDetection_python-opencv/cut-pic"
image_save_path_tail = ".jpg"
for i in range(1,49):
img = cv2.imread( "%s%d%s" % (image_save_path_head, i, image_save_path_tail) )
face_cascade = cv2.CascadeClassifier("H:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml")
if img.ndim == 3:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
else:
gray = img
faces = face_cascade.detectMultiScale3(gray,flags=1, scaleFactor=1.1, outputRejectLevels=True)
rects = faces[0]
neighbours = faces[1]
weights = faces[2]
print("weight of %d is "%(i),rects,neighbours,weights)
</code></pre>
<p>and i get</p>
<blockquote>
<p>weight of 1 is () () () weight of 2
is () () () weight of 3 is () () ()
weight of 4 is () () () weight of 5
is () () () weight of 6 is () () ()
weight of 7 is () () () weight of 8
is () () () weight of 9 is () () ()
weight of 10 is () () () weight of 11
is () () () weight of 12 is () () ()
weight of 13 is () () () weight of 14
is () () () weight of 15 is () () ()
weight of 16 is () () () weight of 17
is () () () weight of 18 is () () ()
weight of 19 is () () () weight of 20
is () () () weight of 21 is () () ()
weight of 22 is () () () weight of 23
is () () () weight of 24 is () () ()
weight of 25 is () () () weight of 26
is () () () weight of 27 is () () ()
weight of 28 is () () () weight of 29
is () () () weight of 30 is () () ()
weight of 31 is () () () weight of 32
is () () () weight of 33 is () () ()
weight of 34 is () () () weight of 35
is () () () weight of 36 is () () ()
weight of 37 is () () () weight of 38
is () () () weight of 39 is () () ()
weight of 40 is () () () weight of 41
is () () () weight of 42 is () () ()
weight of 43 is () () () weight of 44
is () () () weight of 45 is () () ()
weight of 46 is [[ 4 10 37 37]]
[[25]] [[ 7.2749402]] weight of 47 is
() () () weight of 48 is [[ 0 13 32
32]] [[25]] [[ 8.64948004]]</p>
</blockquote>
http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?answer=220343#post-id-220343You needed unpack for `detectMultiScale3` in order to get `for x,y,w,h in faces:` to get it working.
faces, w, n = face_cascade.detectMultiScale3(gray, scaleFactor=1.3,
minNeighbors=5,
minSize=(100, 100),
outputRejectLevels=True)
print(f'w :', w)
print(f'n :', n)
Thu, 24 Oct 2019 09:44:27 -0500http://answers.opencv.org/question/179696/python-facedetection-detectmultiscale/?answer=220343#post-id-220343