gpt4 book ai didi

numpy - python opencv2,错误的摄像头界面,仅cam light

转载 作者:行者123 更新时间:2023-12-02 16:11:36 24 4
gpt4 key购买 nike

这是opencv2 Takeimage按钮的代码。
它无法正常工作,仅凸轮灯亮起,但相机界面未显示:

def TakeImage():
Id=(txt.get())
name=(txt2.get())
if(is_number(Id) and name.isalpha()):
Video= cv2.VideoCapture(0)
harcascadePath = "haarcascade_frontalfacedafults_.xml"
detector=cv2.CascadeClassifier(harcascadePath)
sampleNum=0
while(True):
ret,img=Video.read();
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=detector.DetectMultiScale(gray,1.2,5);
for(x,y,w,h) in faces:
cv2.recatangle(img,(x,y),(x+w,y+h),(255,0,0),2)
sampleNum=sampleNum+1
cv2.imwrite("TrainImages\ "+name +"."+Id +'.'+str(samlpeNum)+".jpg",gray[y:y+h,x:x+h])
cv2.imshow('Frame',img)
if cv2.waitKey(100) &0XFF == ord('s'):
break
elif sample>60:
break
Video.release()
cv2.destroyAllWindows()
res = "Images Saved for ID: "+ Id + " Name : "+ name
row = [Id, Name]
with open ('studentDetails\studentDetails.csv','a+') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(row)
csvFile.close()
message.configure(text=res)
else:
if(is_number(Id)):
res ="Enter Alphabetical Name"
message.configure(text= res)
if (name.isalpha()):
res="Enter Numberic Id"
message.configure(text=res)

显示错误:

Exception in Tkinter callback Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\tkinter__init__.py", line 1705, in call return self.func(*args) File "C:\Users\Lenovo\Desktop\face reconiger system.py", line 87, in TakeImage faces=detector.DetectMultiScale(gray,1.2,5); AttributeError: 'cv2.CascadeClassifier' object has no attribute 'DetectMultiScale'

最佳答案

.xml文件的路径看起来不正确。您需要替换以下行:

harcascadePath = "haarcascade_frontalfacedafults_.xml"


harcascadePath = cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'

关于numpy - python opencv2,错误的摄像头界面,仅cam light,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61849262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com