2016-09-30 6 views
1

Webカメラの出力に線を描こうとしています。しかし、私は以下のコードで、特に描画線関数の "img"部分に問題があります。私は別のイメージにイメージを追加する例が数多くあるので、それらの例を参照しないでください。これは、具体的には、ウェブカメラ出力の出力の線または四角形の問題です。以下はWebcamストリーム上に線を描く-Python

cv2.line(img= vc, pt1= 10, pt2= 50, color =black,thickness = 1, lineType = 8, shift = 0) 

完全なコードです:

import cv2 

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

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() 
    key = cv2.waitKey(20) 
    if key == 27: # exit on ESC 
     break 
    else: 
     cv2.line(img= vc, pt1= 10, pt2= 50, color =black,thickness = 1, lineType = 8, shift = 0) 
vc.release() 
cv2.destroyWindow("preview") 

答えて

2

あなたはあなたが得るframe上に線を描画する必要があります。以下を試してください:

import cv2 

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

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() 
    key = cv2.waitKey(20) 
    if key == 27: # exit on ESC 
     break 
    else: 
     cv2.line(img=frame, pt1=(10, 10), pt2=(100, 10), color=(255, 0, 0), thickness=5, lineType=8, shift=0) 

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

ありがとう@ martin-evans。これはうまくいった。 without()を付けずにvcを印刷する際に問題がありました。 VCを印刷する目的が何であるかわからないので、この場合は削除しましたか? – TsTeaTime

+1

あなたはそれを削除することができます、私は私のウェブカメラが接続されていることをチェックしていた。 –

+0

それを手に入れました...助けてくれてありがとう – TsTeaTime

関連する問題