Python opencv

Hello everyone I have a problem regarding python and openCV. I want to make a rectangle in the middle of a video stream I was able to do it with a static image using the PIL library 

CODE:

from PIL import Image, ImageDraw
im = Image.open("test1.jpg")
draw = ImageDraw.Draw(im)
draw1 = ImageDraw.Draw(im)
draw2 = ImageDraw.Draw(im)
draw3 = ImageDraw.Draw(im)
draw.line((192,1, 192,480), fill=255)
draw1.line((395,1, 395,480), fill=255)
draw2.line((1,50, 640,50), fill=255)
draw3.line((1,305, 640,305), fill=255)

im.show()

######################################################################################## 
I don’t understand how to do it with the opencv library I have been trying for weeks and the
python opencv documentation is not that helpful or detailed I found this
adapting the way he did it I made a program
from PIL import Image, ImageDraw
import cv2
import numpy
im = Image.open(“test1.jpg”)
im = cv2.line(im,(0,0),(511,511),(255,0,0),5)

im.show()


but I get an error
saying “TypeError: img is not a numpy array, neither a scalar”.
So do you guys have any suggestions or information.

Thank you 

well… you have an

well… you have an error. 

1st option: copy error… paste in google and see what it gives. Did you do that?

2nd option: the error is descriptive enough… the method seems to espect either a numpy array or a scalar so I threw this at google:

"opencv convert img to numpy array"

first result: http://stackoverflow.com/questions/7762948/how-to-convert-an-rgb-image-to-numpy-array/7776579#7776579

It’s error solving 101.

 

I did everything exactly

I did everything exactly before and I read the stackoverflow page already, it was not really what I was looking for since I am doing this with the opencv library.

Sorry there bud… but have

Sorry there bud… but have you really really READ the link I’ve shown (and you seemingly saw before)?? 

From there:

You can use newer OpenCV python interface (if I’m not mistaken it is available since OpenCV 2.2). It natively uses numpy arrays:

import cv2
im
= cv2.imread(“abc.tiff”)
print type(im)

result:

<type ‘numpy.ndarray’>

 

Are we talking the same language? I’m not giving you a fish… I trying to teach how to fish. If you really visited that link before, you need to pay more attention. So… if I present you with a opencv solution… and you say that you didn’t really want it because what you wanted was actually that same I gave you (and you found earlier)? confused

**Thank you **

Thank you guys that was the final touch in my program. On an other note the program I made does not have anything to do with robotics am I allowed to share it here(on LMR).

I suppose you forgot the

I suppose you forgot the question mark, if so yes unless it’s really something way way off.

But there’s the “Something else” category and the “Blog” that might then be suitable for that. If it’s just something that you’ve done as training to learn openCV or other stuff I advise a Blog post, if it’s something of general use/interest that would benefit others then a Something else might be in order.

As for subjects, electronics and programming that is at least tangencially connected to robots it’s ok.

It has a lot to do with

It has a lot to do with Artificial Intelligence, communication, and computer vision.

Maybe I will post it in Something else.