我想从相机抓取图像,并将其左右翻转,这样视图的效果就像一面镜子。不过,我也喜欢在视图中添加一些文本,但结果是使用np.fliplr(frame)
翻转图像后,cv.putText
就不再工作了。在
下面是我使用python 3.5.2
的最小示例:
import numpy as np
import cv2
import platform
if __name__ == "__main__":
print("python version:", platform.python_version())
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
cv2.putText(frame,'Hello World : Before flip',(100, 100), cv2.FONT_HERSHEY_SIMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
frame = np.fliplr(frame)
cv2.putText(frame,'Hello World : After flip',(100, 200), cv2.FONT_HERSHEY_SIMPLEX, 1,(255,255,255),2,cv2.LINE_AA)
# Process the keys
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
print("quit")
break
# show the images
cv2.imshow('frame',frame)
cap.release()
cv2.destroyAllWindows()
我怀疑是因为
cv2.putText
与np.array
不兼容,后者是np.fliplr(frame)
的返回值。我建议您改用frame = cv2.flip(frame, 1)
。在相关问题 更多 >
编程相关推荐