1

When I run the following code I can take a picture with my Raspberry Pi B

#!/usr/bin/env python

import picamera
from time import sleep

camera = picamera.PiCamera()
camera.start_preview()
camera.vflip = True
camera.iso = 400
sleep(3)
camera.capture('image.jpg')
camera.stop_preview()

But as soon as I try and run the code runs

print ("Taking pics")

now = time.strftime("%Y-%m-%d-%H-%M-%S") #get the current date and time for the start of the filename

if config.capture_count_pics:
    try: # take the photos
        for i in range(1,total_pics+1):
            camera.hflip = True # preview a mirror image
            camera.start_preview(resolution=(config.monitor_w, config.monitor_h)) # start preview at low res but the right ratio
            time.sleep(2) #warm up camera
            #GPIO.output(led_pin,True) #turn on the LED
            filename = config.file_path + now + '-0' + str(i) + '.jpg'
            camera.hflip = False # flip back when taking photo
            camera.capture(filename)
            print(filename)
            #GPIO.output(led_pin,False) #turn off the LED
            camera.stop_preview()
            show_image(real_path + "/pose" + str(i) + ".png")
            time.sleep(capture_delay) # pause in-between shots
            clear_screen()
            if i == total_pics+1:
                break
    finally:
        camera.close()
else:
    camera.start_preview(resolution=(config.monitor_w, config.monitor_h)) # start preview at low res but the right ratio
    time.sleep(2) #warm up camera

    try: #take the photos
        for i, filename in enumerate(camera.capture_continuous(config.file_path + now + '-' + '{counter:02d}.jpg')):
            #GPIO.output(led_pin,True) #turn on the LED
            print(filename)
            time.sleep(capture_delay) # pause in-between shots
            #GPIO.output(led_pin,False) #turn off the LED
            if i == total_pics-1:
                break
    finally:
        camera.stop_preview()
        camera.close()

I get an error:

File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 2044, in _negotiate_format
mmal.MMAL_EINVAL, 'failed to negotiate port format')
picamera.exc.PiCameraMMALError: failed to negotiate port format: Argument is invalid
Ended abruptly
Error in atexit._run_exitfuncs:
Traceback (most recent call last):

and I have no idea why, or where to even begin troubleshooting

Traceback

    Taking pics
    mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
    mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x1e0a150 (EINVAL)
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x1e0a150 (EINVAL)
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x1e0a150 (EINVAL)
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x1e0a150 (EINVAL)
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x1e0a150 (EINVAL)
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x1e0a150 (EINVAL)
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 151, in _run_module_as_main
    mod_name, loader, code, fname = _get_module_details(mod_name)
  File "/usr/lib/python2.7/runpy.py", line 101, in _get_module_details
    loader = get_loader(mod_name)
  File "/usr/lib/python2.7/pkgutil.py", line 464, in get_loader
    return find_loader(fullname)
  File "/usr/lib/python2.7/pkgutil.py", line 474, in find_loader
    for importer in iter_importers(fullname):
  File "/usr/lib/python2.7/pkgutil.py", line 430, in iter_importers
    __import__(pkg)
  File "drumminhands_photobooth.py", line 371, in <module>
    start_photobooth()
  File "drumminhands_photobooth.py", line 250, in start_photobooth
    camera.start_preview(resolution=(config.monitor_w, config.monitor_h)) # start preview at low res but the right ratio
  File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 800, in start_preview
    self, self._camera.outputs[self.CAMERA_PREVIEW_PORT], **options)
  File "/usr/lib/python2.7/dist-packages/picamera/renderers.py", line 477, in __init__
    self.renderer.inputs[0].connect(source).enable()
  File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 1296, in connect
    return other.connect(self, **options)
  File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 1304, in connect
    return MMALConnection(self, other, **options)
  File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 2141, in __init__
    super(MMALConnection, self).__init__(source, target, formats)
  File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 1986, in __init__
    self._negotiate_format(formats)
  File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 2044, in _negotiate_format
    mmal.MMAL_EINVAL, 'failed to negotiate port format')
picamera.exc.PiCameraMMALError: failed to negotiate port format: Argument is invalid
Ended abruptly
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "drumminhands_photobooth.py", line 85, in cleanup
    pygame.quit()
AttributeError: 'NoneType' object has no attribute 'quit'
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "drumminhands_photobooth.py", line 85, in cleanup
    pygame.quit()
AttributeError: 'NoneType' object has no attribute 'quit'
  • 1
    Can you also post the traceback? – Bex Aug 18 '17 at 11:33
  • Without the full traceback I'm not sure exactly what's going on but I'll hazard a guess that monitor_w and monitor_h might not be what you're expecting when start_preview is called (might be worth throwing a print statement before that to check them); that's the only place that I'd expect to see that error in the posted script – Dave Jones Aug 18 '17 at 21:13
  • I have posted the traceback. The code that I am trying to run comes from this project on github github.com/drumminhands/drumminhands_photobooth It is failing when I run the drumminhands_photobooth.py file. – Tom Aug 19 '17 at 2:05
0

I was able to fix this, by changing the config file. Updating the hi_res_pics field from False to True, made the whole process start working.

Thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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