Flipping the camera in diddyRedWeb.py etc

Trying to find where to edit web interface software to flip the camera image as I now have the camera on a pan & tilt head with the camera module mounted upside down and can't change it physically so need to flip the image. Can anyone help?

I have found
camera.hflip = True
camera.vflip = True
in picamera documentation but have no idea how/where in the DiddyBorg software to find and edit this?

piborg's picture

This is actually a fairly simple change, the Web UI is already flipping the image :)

On line 113 we use OpenCV to flip the image horizontally and vertically:
flippedArray = cv2.flip(self.stream.array, -1) # Flips X and Y
The value passed tells it which way to flip the image:

  • 0 → Flip vertically (Y)
  • 1 → Flip horizontally (X)
  • -1 → Flip vertically and horizontally (X & Y)

To get the image without any flipping we can change lines 113 to 115 so that we do not perform the flip:

                    # Read the image and save globally
                    self.stream.seek(0)
                    #flippedArray = cv2.flip(self.stream.array, -1) # Flips X and Y
                    retval, thisFrame = cv2.imencode('.jpg', self.stream.array)
                    #del flippedArray
                    lockFrame.acquire()
                    lastFrame = thisFrame
                    lockFrame.release()

This will effectively rotate the image by 180°, which I think is probably what you are after.

Thanks for your help.

Just been trying to run diddyredfollowball and he seems to turn away as he get closer. Is this something to do with camera flip? As I still have the camera module (v2.1) mounted upside down. See pic

Images: 
piborg's picture

Yes, it is probably that the code is getting confused between left and right.

This line determines the direction to travel towards the ball in the image:
direction = (x - imageCentreX) / imageCentreX
What you want to do is flip the direction around like this:
direction = (imageCentreX - x) / imageCentreX

Subscribe to Comments for "Flipping the camera in diddyRedWeb.py etc"