diddyborg joyball
Forums:
Hi, how would I use this script without the camera streaming but rather have a preview constantly on and viewed on a screen?
Thanks
- Log in to post comments
Hi, how would I use this script without the camera streaming but rather have a preview constantly on and viewed on a screen?
Thanks
piborg
Thu, 02/08/2018 - 11:05
Permalink
Preview image
Showing the image on a monitor attached directly to the Pi is not too difficult, it just needs a few extra lines to create the screen and display it.
First you need to create a display where the image can be shown:
# Startup sequence print 'Setup camera' camera = picamera.PiCamera() camera.resolution = (imageWidth, imageHeight) camera.framerate = frameRate imageCentreX = imageWidth / 2.0 imageCentreY = imageHeight / 2.0 print 'Setup the stream processing threads' processingPool = [StreamProcessor() for i in range(threadCount)] print 'Wait ...' time.sleep(2) captureThread = ImageCapture() print 'Create a window to show images' cv2.namedWindow('preview', cv2.WINDOW_NORMAL)Second you will want to grab the original image and draw the contours onto it:
# Image processing function def ProcessImage(self, image): global autoMode # Get the red section of the image previewImage = image.copy() image = cv2.medianBlur(image, 5) image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV) # Swaps the red and blue channels! red = cv2.inRange(image, numpy.array((115, 127, 64)), numpy.array((125, 255, 255))) # Find the contours contours,hierarchy = cv2.findContours(red, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # Draw the contours cv2.drawContours(previewImage, contours, -1, (0,0,255), 1) # Go through each contour foundArea = -1 foundX = -1 foundY = -1Third you need to send the image to the window:
# Image processing function def ProcessImage(self, image): global autoMode # Get the red section of the image previewImage = image.copy() image = cv2.medianBlur(image, 5) image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV) # Swaps the red and blue channels! red = cv2.inRange(image, numpy.array((115, 127, 64)), numpy.array((125, 255, 255))) # Find the contours contours,hierarchy = cv2.findContours(red, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # Draw the contours cv2.drawContours(previewImage, contours, -1, (0,0,255), 1) # Display the image cv2.imshow('preview', previewImage) cv2.waitKey(1) # Go through each contour foundArea = -1 foundX = -1 foundY = -1You may also have to comment out this line to make the display work correctly:
If you want your DiddyBorg to stay put when running the script just change the output voltage to 0: