bohrhilfe.py
1 | #!/usr/bin/python
| 2 |
| 3 | # Es wird das Paket python-opencv benoetigt!
| 4 |
| 5 | import cv
| 6 |
| 7 | class DrillHelp:
| 8 | def __init__(self, camera_id = 0):
| 9 | self.mirror_image = True
| 10 | self.cross = (50, 50)
| 11 | cv.NamedWindow("camera", 1)
| 12 | cv.SetMouseCallback('camera', self._set_cross, None)
| 13 | self.capture = cv.CreateCameraCapture(camera_id)
| 14 | height = int(cv.GetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT))
| 15 | width = int(cv.GetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_WIDTH))
| 16 | self.img = cv.CreateImage( (width, height), 8, 3)
| 17 |
| 18 | def _set_cross(self, event, x, y, flags, foo):
| 19 | if event == cv.CV_EVENT_LBUTTONDOWN:
| 20 | self.cross = (x, y)
| 21 |
| 22 | def _draw_cross(self):
| 23 | cv.Circle(self.img, self.cross, 33, cv.RGB(255, 255, 255), 2)
| 24 | cv.Circle(self.img, self.cross, 13, cv.RGB(255, 255, 255), 1)
| 25 | cv.Line(self.img, (self.cross[0] - 20, self.cross[1] -20), (self.cross[0] + 20, self.cross[1] + 20), cv.RGB(0,200,0), 1)
| 26 | cv.Line(self.img, (self.cross[0] + 20, self.cross[1] -20), (self.cross[0] - 20, self.cross[1] + 20), cv.RGB(0,200,0), 1)
| 27 |
| 28 | def run(self):
| 29 | while True:
| 30 | frame = cv.QueryFrame(self.capture)
| 31 | if self.mirror_image:
| 32 | cv.Flip(frame, self.img, 0)
| 33 | else:
| 34 | cv.Copy(frame, self.img)
| 35 | self._draw_cross()
| 36 | cv.ShowImage("camera", self.img)
| 37 | k = cv.WaitKey(10)
| 38 | if k != -1:
| 39 | break
| 40 | del(self.capture)
| 41 |
| 42 | if __name__ == '__main__':
| 43 | d = DrillHelp()
| 44 | d.run()
|
|