- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我对此进行了大量研究,我认为我的逻辑已经过时了,几乎已经到了,但似乎无法理解为什么 cv2.imshow() 窗口中没有显示任何内容只是一个灰色框,但是好消息我是否能够检测到人脸并裁剪该人脸,然后将其保存在文件夹中。
你能告诉我哪里出了问题吗
#Author: Waheed Rafiq
#Research Student Birmingham City University
#Date: 03/11/2016
#Description :detect and Save capture face in a folder.
#Import library required for Capture face.
import cv2
#import the cascade for face detection
FaceClassifier =cv2.CascadeClassifier
('haarcascade_frontalface_default.xml')
# access the webcam (every webcam has
capture = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = capture.read()
if not capture:
print "Error opening webcam device"
sys.exit(1)
# to detect faces in video
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = FaceClassifier.detectMultiScale(gray, 1.3, 5)
# Resize Image
minisize = (frame.shape[1],frame.shape[0])
miniframe = cv2.resize(frame, minisize)
# Store detected frames in variable name faces
faces = FaceClassifier.detectMultiScale(miniframe)
# Draw rectangle
for f in faces:
x, y, w, h = [ v for v in f ]
cv2.rectangle(frame, (x,y), (x+w,y+h), (255,255,255))
#Save just the rectangle faces in SubRecFaces
sub_face = frame[y:y+h, x:x+w]
FaceFileName = "unknowfaces/face_" + str(y) + ".jpg"
cv2.imwrite(FaceFileName, sub_face)
#Display the image
cv2.imshow('Result',frame)
break
# When everything done, release the capture
img.release()
cv2.waitKey(20)
cv2.destroyAllWindows()
非常感谢您的支持
最佳答案
我不得不修改我的代码,并再次重新思考逻辑:对于那些希望知道如何使用 Opencv 从网络摄像头或 Raspberry PI 检测人脸然后裁剪检测到的人脸的人,这就是您的做法在 python 2.7 中使用 OpenCV 2.4.12
# croppfacedetection.py
#Author: Waheed Rafiq
#Research Student Birmingham City University
#Date: 03/11/2016
#Description : Save capture face in a folder.
#Import library required for Capture face.
# Should you wish to use this code for
#education purpose in your assignment or dissertation
# please use the correct citation and give credit where required.
import cv2
size = 4
webcam = cv2.VideoCapture(0) #Use camera 0
# We load the xml file
classifier = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Above line normalTest
#classifier = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
#Above line test with different calulation
#classifier = cv2.CascadeClassifier('haarcascade_frontalface_alt_tree.xml')
#classifier = cv2.CascadeClassifier('lbpcascade_frontalface.xml')
while True:
(rval, im) = webcam.read()
im=cv2.flip(im,1,0) #Flip to act as a mirror
# Resize the image to speed up detection
mini = cv2.resize(im, (im.shape[1] / size, im.shape[0] / size))
# detect MultiScale / faces
faces = classifier.detectMultiScale(mini)
# Draw rectangles around each face
for f in faces:
(x, y, w, h) = [v * size for v in f] #Scale the shapesize backup
cv2.rectangle(im, (x, y), (x + w, y + h),(0,255,0),thickness=4)
#Save just the rectangle faces in SubRecFaces
sub_face = im[y:y+h, x:x+w]
FaceFileName = "unknowfaces/face_" + str(y) + ".jpg"
cv2.imwrite(FaceFileName, sub_face)
# Show the image
cv2.imshow('BCU Research by Waheed Rafiq (c)', im)
key = cv2.waitKey(10)
# if Esc key is press then break out of the loop
if key == 27: #The Esc key
break
请记住,您将需要创建一个文件夹,并且在该区域内您将需要一个名为 unknowfaces 的文件夹,从该文件夹的根目录运行脚本,它应该将检测到的所有面孔保存到 unknowfaces 文件夹中。有关此代码的更多信息将很快在我的网站上提供
waheedrafiq.net
关于Python OpenCV 活体人脸检测裁剪保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40408414/
我正在寻找一种用C# 编写的人脸、情感和语音识别方法。对于人脸识别,我早期使用的是 Emgu CV,它不准确,而且在弱光条件下性能非常低。我还需要找到用户的情绪。不管是悲伤还是快乐。但我发现使用 Em
我正在尝试使用 Apple 的 ARKit 3.0(Reality Kit)设置面部 anchor 但失败了。1. 以前只支持前置摄像头。现在还是这样吗?2.如何让Reality Kit的ARView
当我调试人脸 API 时抛出以下错误。 UnknownHostException@830035410936}“java.net.UnknownHostException:无法解析主机“api.proj
用例如下 我们的系统中有面孔列表 用户将上传一张图片 我们希望显示与上传图像匹配的面孔列表,例如置信度 >0.8 现在查看how to ,我的理解如下 使用人脸检测API,我们需要首先上传所有图像,包
用例如下 我们的系统中有面孔列表 用户将上传一张图片 我们希望显示与上传图像匹配的面孔列表,例如置信度 >0.8 现在查看how to ,我的理解如下 使用人脸检测API,我们需要首先上传所有图像,包
我正在寻找一种完美的方法来平滑二进制图像的边缘。问题是二值图像似乎是一个阶梯状的边界,这对我进一步的掩蔽过程来说非常不愉快。 我附加了一个原始二进制图像,该图像将被转换为平滑边缘,并且我还提供了预期的
我需要一个 java 库来确定哪个图像是“人体”;这是一张“人脸”;这是一个“动物”;这是一个“风景”等等。 有这样的东西吗? 谢谢 最佳答案 我不认为那里有什么方便的东西。特别是因为你在这里有非常广
自从过去 2 天以来,我一直在努力弄清楚出了什么问题?我正在使用 Microsoft 认知服务开发用于人脸识别的 Cordova android 应用程序。为了拍摄图像,我使用了 Cordova Ca
我是一名优秀的程序员,十分优秀!