I'm using python 3.4 with a raspberry pi camera connected through csi port on a Pi3.

I'm trying to write a program which should control the PiCamera settings through a webpage with Flask. I'm trying to update the vflip and hflip settings (toggling from False to True and back again).

The code seems to work from the initial switch from False to True. I get the updated image stream with the flipped orientation. But when I try to update the settings more than once, if doesn't seem to work.

I have a camera thread which gets updated with the new values:

def set_vflip(self, value):
    if self.camera is not None:
        print("updated to " + value)
        self.camera.vflip = value

So my output is:

updated to True

(image is also actually flipped as excepted)

updated to False

(command doesn't seem to work anymore)

According to http://picamera.readthedocs.io/en/release-1.10/api_camera.html#picamera.camera.PiCamera.hflip I should be able to call this method while the image capture is running. But I cannot disable it from True to False. This problem is on hflip and vflip property of the PiCamera object.

When I run the code manually in a python interpreter shell it seems to works:

from picamera import PiCamera
cam = PiCamera()
cam.vflip = True
cam.vflip = False

but running the same code inside a thread with some helper functions doesn't seem to have the same effect. I call set_vflip function from above first with True, and after some time with False, but it doesn't flip back.

Is this option not working properly with multithreaded environments? Or what could possibly cause this behaviour?

I also modified my code and added a queue for changing the vflip values, so that only the thread changes this setting which also created the PiCamera instance. But this doesn't seem to have any effect either.

Any input on how to fix this behaviour highly appreciated.

1 Answer 1


The value you're passing to set_vflip is a str. You can tell this because if you attempt your print statement at the command line with a literal bool it fails:

$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("updated to " + True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'bool' object to str implicitly

In other words, you're passing "True" instead of True and "False" instead of False. Python's truth test considers any non-empty string to be True, ergo you're always setting vflip on. You need to either pass a "proper" bool to set_vflip or alter set_vflip to handle the conversion itself, e.g.:

def set_vflip(self, value):
    value = (value == "True")
    if self.camera is not None:
        print("updated to " + value)
        self.camera.vflip = value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.