这是我的代码:
import os
import cv2
import uuid
import time
camera = cv2.VideoCapture(0)
POZ_Dosya = os.path.join("veriler", "pozitif")
NEG_Dosya = os.path.join("veriler", "negatif")
Temel_Dosya = os.path.join("veriler", "temel")
os.makedirs(POZ_Dosya, exist_ok=True)
os.makedirs(NEG_Dosya, exist_ok=True)
os.makedirs(Temel_Dosya, exist_ok=True)
target_size = 250
while camera.isOpened():
ret, frame = camera.read()
scale_percent = 33
width = int(frame.shape[1] * scale_percent / 100)
height = int(frame.shape[0] * scale_percent / 100)
dim = (width, height)
frame = cv2.resize(frame, dim, interpolation=cv2.INTER_AREA)
height, width, _ = frame.shape
start_row = max(0, int((height - target_size) / 2))
end_row = min(height, start_row + target_size)
start_col = max(0, int((width - target_size) / 2))
end_col = min(width, start_col + target_size)
frame = frame[start_row:end_row, start_col:end_col, :]
frame = cv2.resize(frame, (target_size, target_size))
cv2.imshow("a", frame)
if cv2.waitKey(1) & 0xFF == ord("a"):
time.sleep(10)
imagename = os.path.join(Temel_Dosya, '{}.jpg'.format(uuid.uuid1()))
cv2.imwrite(imagename, frame)
if cv2.waitKey(1) & 0xFF == ord("p"):
pass
if cv2.waitKey(1) & 0xFF == ord("q"):
break
camera.release()
cv2.destroyAllWindows()
我该如何解决这个问题。
提前致谢。
我试图为数据集拍摄大量照片,但保存时它会冻结并且需要很长时间才能保存。我已经添加了
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.organizeImports": "never"
我在 VS code 上的setting.js 仍然继续运行
这不是正确的使用方法
cv2.waitKey()
删除两个
cv2.waitKey()
尝试这样的事情:
key = cv2.waitKey(0)
if key == ord('p'):
<Do something>
elif key == ord('q'):
break
elif key == 27:
flag = False