-1

I'm trying to work with Python, opencv and simplecv. I want to capture an image using a camera and then draw a 'freeform' 'filled' area over the captured image using Mouse. Can somebody please help me accomplish this. Here is what I have done till now:

from SimpleCV import Camera, Display, Image, Color

cam = Camera()
display = Display()
img = cam.getImage()
img.save(display)

while not display.isDone():
    if display.mouseLeft:
        img.dl().circle((display.mouseX, display.mouseY), 4, Color.WHITE, filled=True)
        img.save(display)
        img.save("draw.png")

I can draw over the captured Image, but only with circles. That too are placed far too wide if I draw with normal speed. Here's how it looks:

The drawing done over captured image

Whereas I am trying to achieve something like this:

This is how I want to draw the area

Can somebody help me out?

furas
  • 134,197
  • 12
  • 106
  • 148
Max
  • 105
  • 1
  • 3
  • first show your code and full error message (in question). – furas Dec 06 '16 at 11:33
  • simple example which draw clickable buttons on frame from camera - openCV - https://github.com/furas/my-python-codes/blob/master/cv2/display-button/main.py – furas Dec 06 '16 at 11:34
  • Hi @furas, Thanks for the reply. As I said I've just begun working with SimpleCV, OpenCV and don't know much and still learning. Just simple image capture using the following: `code` cam = Camera() img = cam.getImage() img.show() `code` I dont know how to proceed. Coudn't find anything related to this. I just want to Capture an Image using a camera. Then I want to mark out an area of the captured image by drawing a freeform area filled with any color using mouse. – Max Dec 06 '16 at 12:41
  • check code in link in previous comment. – furas Dec 06 '16 at 12:49
  • @furas : I've updated my post with what I have been able to do till now. – Max Dec 06 '16 at 13:40
  • istead of drawing circles (and save in file) better keep mouse position on list to draw later some polygon (and save all at the end) – furas Dec 06 '16 at 13:43

1 Answers1

0

Keep mouse position on list and draw polygon:

from SimpleCV import Camera, Display, Image, Color

cam = Camera()
display = Display()
img = cam.getImage()
img.save(display)

points = []

while not display.isDone():
    if display.mouseLeft:
        point = (display.mouseX, display.mouseY)

        points.append( point )

        if len(points) > 2:
            img.dl().polygon(points, filled=True, color=Color.RED)

        img.dl().circle(point, 4, Color.WHITE, filled=True)

        img.save(display)
        img.save("draw.png")

Read SimpleCV doc: Drawing on Images in SimpleCV

furas
  • 134,197
  • 12
  • 106
  • 148
  • Thanks a lot @furas . It is eaxctly what I needed. You are a **Lifesaver**. I am going through the documentation, still miles to go. Regards Max. :) – Max Dec 06 '16 at 14:25