我正在使用OpenCV编写一个人脸检测脚本
这是我的代码:
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
if k%256 == 32:
# SPACE pressed
print(my_random_string(9)) # For example, D9E50C
img_name = "face_{}.png".format(img_counter)
cv2.imwrite(img_name, frame[[[(x, y), (x+w, y+h), (0, 255, 0), 2]]])
print("{} written!".format(img_name))
img_counter += 1
# Display the resulting frame
cv2.imshow('FaceDetection', frame)
但我得到了以下错误:
This is screenshot for the error
> c:\Users\Bakri\Desktop\FaceDetection-master\FaceDetection.py:39: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
cv2.imwrite(img_name, frame[[[(x, y), (x+w, y+h), (0, 255, 0), 2]]])
Traceback (most recent call last):
File "C:\Users\Bakri\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\Users\Bakri\Desktop\FaceDetection-master\FaceDetection.py", line 39, in <module>
cv2.imwrite(img_name, frame[[[(x, y), (x+w, y+h), (0, 255, 0), 2]]])
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
Press any key to continue . . .
我搜索了堆栈溢出,但找不到任何相关的问题/答案
好的,这是保存相机拍摄图像的完整代码 它保存所有摄影机窗口(面和全身) 我希望它只保存覆盖着矩形的面
此行保存相机中的所有图像:
我尝试通过以下代码仅保存矩形图像:
但我还是犯了那个错误
相关问题 更多 >
编程相关推荐