Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The next example is similar to the crosshairs example shown earlier in this chapter. However, unlike the earlier example that fixed the crosshairs in the middle of the screen, this example lets the user control where it is aiming by clicking the left mouse button.
from SimpleCV import Camera, Color, Display
cam = Camera()
size = cam.getImage().size()
disp = Display(size)
center = (size[0] /2, size[1] / 2)
while disp.isNotDone():
img = cam.getImage()
img = img.flipHorizontal()
if disp.mouseLeft:
center = (disp.mouseX, disp.mouseY)
# The remainder of the example is similar to the
# short version from earlier in the chapter
# Inside circle
img.dl().circle(center, 50, Color.BLACK, width = 3)
# Outside circle
img.dl().circle(center, 200, Color.BLACK, width = 6)
# Radiating lines
img.dl().line((center[0], center[1] - 50), (center[0], 0),
Color.BLACK, width = 2)
img.dl().line((center[0], center[1] + 50), (center[0], size[1]),
Color.BLACK, width = 2)
img.dl().line((center[0] - 50, center[1]), (0, center[1]),
Color.BLACK, width = 2)
img.dl().line((center[0] + 50, center[1]), (size[0], center[1]),
Color.BLACK, width = 2)
img.save(disp)