Ask Your Question
0

Python openCV drawing functions does not work?!

asked 2014-06-11 12:55:41 -0600

updated 2020-05-21 07:17:39 -0600

supra56 gravatar image

Hi, today I tried to draw a line in a window, this is the code I used.

import numpy as np
import cv2

# Create a black image
img = np.zeros((512,512,3), np.uint8)

# Draw a diagonal blue line with thickness of 5 px
cv2.line(img,(0,0),(511,511),(255,0,0),5)

The problem is that when I run this, I get no errors and the Shell comes up and start running but the window to show the video never pops up or anything, nothing happens. Am I missing some plugin or something that I need to run this?

I got OpenCV and Matplotlib installed for Python.

Heelp please! =(

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-07-11 14:14:43 -0600

li8bot gravatar image

updated 2020-05-21 07:19:08 -0600

supra56 gravatar image

Actually I had the same problem.All you need to do is:

img = np.zeros((512,512,3), np.uint8)
img1= cv2.line(img,(0,0),(511,511),(255,0,0),5)

Thats it..renaming the variable for line does the trick.Now you can use imshow to display the image. Do visit my blog li8bot for further info on opencv with python

edit flag offensive delete link more
0

answered 2020-01-16 00:13:28 -0600

updated 2020-05-21 07:18:26 -0600

supra56 gravatar image

This problem also occurred with me this morning, while i started leaning OpenCV, below solution worked for me, probably this will work for you people also:

import numpy as np
import cv2

img = np.zeros((512, 512, 3), np.uint8)
img= cv2.line(img, (0, 0), (511, 511), (255, 0, 0), 5)

cv2.imshow("Image", img)
cv2.waitKey(0)

Basically, window with line disappears in mili-seconds, so we just need to **add a infinite wait key so that window does not get disappear automatically.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-06-11 12:55:41 -0600

Seen: 3,330 times

Last updated: May 21 '20