cv2.putText,fillConvexPoly和circle返回“位置参数跟随关键字参数”

时间:2018-12-28 00:02:12

标签: python opencv

我需要在网络摄像头上写东西。我在Python中使用openCV。我已经测试了putText,fillConvexPoly和circle都返回错误“位置参数跟随关键字参数”,但是lines方法(aws cloudformation package)可以正常工作。有什么想法我做错了吗?

sam build

1 个答案:

答案 0 :(得分:0)

您需要将点声明为numpy数组,cv2.fillConvexPoly仅接受5个参数。并且按下键退出必须在cv2.waitKey期间进行,否则您将无法停止捕获。

尝试一下。

import cv2
import random
import numpy as np

cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX

if vc.isOpened(): # try to get the first frame
    rval, frame = vc.read()
else:
    rval = False

while rval:

    cv2.imshow("preview", frame)
    rval, frame = vc.read()
    if cv2.waitKey(20) & 0xFF == ord('q'):#hit q to close
        break
    else:
        pts = np.array(((300,300), 
                        (random.randint(0,600), random.randint(0,600)),
                        (20,20),
                        (random.randint(0,600),random.randint(0,600))), dtype=int)
        cv2.fillConvexPoly(frame, pts, (255,0,0),8, 0)
        cv2.putText(frame, 'Good job Self!', (230, 50), font, 0.8, (0, 255, 0), 2, cv2.LINE_AA)

vc.release()
cv2.destroyWindow("preview")