python - 我的python人脸识别项目面临这种类型的错误。摄像头灯亮但不显示摄像头界面
问题描述
我的python人脸识别项目面临这种类型的错误。摄像头灯亮,但不显示摄像头界面。
如果 cv2.waitKey(100) & 0xFF == ord('q'): cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:717 : error: (-2:Unspecified error) 该功能未实现。使用 Windows、GTK+ 2.x 或 Cocoa 支持重建库。如果您使用的是 Ubuntu 或 Debian,请安装
def TakeImages():
Id =(txt.get())
name =(txt2.get())
if(is_number(Id) and name.isalpha()):
cam = cv2.VideoCapture(0)
harcascadePath = "C:/Users/Lenovo/AppData/Local/Programs/Python/Python36/Lib/site-packages/cv2/data/haarcascade_frontalface_default.xml"
detector = cv2.CascadeClassifier(harcascadePath)
sampleNum = 0
while(True):
ret,img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3,5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), ( x + w, y + h), (255, 0, 0), 2)
sampleNum=sampleNum + 1
cv2.imwrite("C:\Users\Lenovo\AppData\Local\Programs\Python\Python36\TrainingImages\ "+name +"."+Id +'.'+ str(sampleNum) + ".jpg", gray[y:y + h, x:x + w])
cv2.imshow('frame', img)
if cv2.waitKey(100) & 0xFF == ord('q'):
break
elif sampleNum>60:
break
cam.release()
cv2.destroyAllWindows()
res = "Images Saved for ID: " + Id +" Name: "+ name
row = [Id, name]
with open('C:/Users/Lenovo/AppData/Local/Programs/Python/Python36/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 Numeric Id"
message.configure(text = res)
Error..
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36\lib\idlelib\run.py", line 137, in main
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36\lib\queue.py", line 172, in get
raise Empty
queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\Lenovo\Desktop\Face recognision syystem36.py", line 96, in TakeImages
if cv2.waitKey(100) & 0xFF == ord('q'):
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:717: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvWaitKey'
解决方案
推荐阅读
- java - 如何修复 CountDownTimer 在 android 应用程序中的错误
- r - 有没有办法根据文本进行过滤?
- javascript - 如果基于特定字段不存在,MongoDB 将项目添加到文档数组
- java - 从国际象棋中搜索国王的每一个方向
- terraform - 如何修复 Terraform 中的 badRequest 错误 400?
- linux - 从没有文件句柄的内存映射文件中清除操作系统缓存
- html - 使用带有变换的位置粘性时出现问题:比例
- ios - 如何使用 Alamofire 更改全局变量?
- java - GcsFilename 的 Eclipse ClassNotFoundException 的 Google Cloud 工具
- python-3.x - 统计基本指令的数量及其类型