Draw Line on Webcam Stream -Python
<p>I am attempting to draw a line to the webcam output. However, I am having difficulty with the following code and specifically with "img" portion of the draw line function. I have seen numerous examples of adding an image to another image, so please don't refer me to those examples. This is specifically a question of a line or square on the output of the webcam output.</p>

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

<p>Below is the full code:</p>

<pre><code>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")
</code></pre>

<p>You need to draw the line on the <code>frame</code> you get. Try the following:</p>

<pre><code>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")   
</code></pre>

python opencv