Ask Your Question
0

Drawing a single pixel in a DrawingLayer

asked 2013-12-13 05:10:30 -0500

Franksm gravatar image

updated 2013-12-13 05:13:38 -0500

I would like to draw a single pixel into a drawinglayer object.

I've found that it's easy to draw lines, text, circles, etc, but I've not been able to find a way to draw a single individual pixel on the layer. Am I missing something? Is it done on purpose?

DrawingLayer has mSurface data member, a pygame surface, which allows such operation by means of setat method, but I don't want to mess with it.

My goal is to draw different information in several DrawingLayers before applying them to the image, and I need this information to have pixel resolution.

An alternative would be drawing a line of length 1 or a circle with radius 1, but I think this is an overkill.

Please let me know your opinion.

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-12-13 08:35:13 -0500

xamox gravatar image

Depends exactly what you are trying to do. It is possible to draw a single point using the drawPoints() method, although the way it looks it might not be exactly what you want, you can try with:

img = Image('simplecv')
img.drawPoints([(10,10)], sz=1,width=1)
img.show()

If that doesn't do what you want, you can always set colors directly using a numpy array.

img = Image('simplecv')
nimg = img.getNumpy()
nimg[10][10] = [255,0,0] #set point at coordinates 10,10 to RGB value of red
img = Image(nimg)
img.show()
edit flag offensive delete link more

Comments

Thanks for your reply. The fact is that I'd not like to change the image, but use DrawingLayers instead. Since I was not able to do that, I followed a solution similar to your second solution. I created a new image with the same size of original image and in that image I set the pixel directly using the array operator img[x, y] = (R, G, B).

Franksm gravatar imageFranksm ( 2014-02-04 07:07:52 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-12-13 05:10:30 -0500

Seen: 396 times

Last updated: Dec 13 '13