unable to get high resolution from usb webcam using pygame

Bug #1857438 reported by cr on 2019-12-24
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Raspbian
Undecided
Unassigned

Bug Description

Package: pygame, Version: 1.9.4.post1 (Location: /usr/lib/python3/dist-packages)

I'm unable to take an image of an usb-camera highter than 160x120 resolution on Raspberry pi 4 with python3, my desired resolution is 640x480.

setup:
RPI4 (1gb), latest raspbian buster(2019-09-26), fully updated (rpi-update): Linux raspberrypi 4.19.88-v7l+ #1284 SMP Wed Dec 11 13:51:57 GMT 2019 armv7l GNU/Linu usb camera: Logitech, Inc. HD Webcam C525

software:

    Python 3.7.3
    Pygame Version: 1.9.4.post1 (Location: /usr/lib/python3/dist-packages)
    pip3: pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)

minimal script I use: (executed as 'sudo python3 test.py')

               pygame.init()
               pygame.camera.init()
               cam = pygame.camera.Camera("/dev/video0",(640,480))
               cam.start()
               image = cam.get_image()
               pygame.image.save(image,'demo_camera.jpg')
               cam.stop()
               pygame.camera.quit()

behaviour:
script hangs when calling cam.get_image() when I change the resolution to 160x120 (or lower) it works and generates an image of 160x120

When I put the sd card into my RPI3 the script works with my desired resolution of 640x480.

The camera itself is able to capture images of 640x480, the following command results in a picture of requested resolution:
fswebcam -r 640x480 image.jpg
fswebcam -r 1280x720 image.jpg

relevant information:
the usb camera creates 2 /dev/video devices, behaviour described here by someone else: https://raspberrypi.stackexchange.com/questions/100395/single-webcam-using-dev-video0-and-dev-video1

cr (cr-newton) wrote :

By solving another problem I found out it was related and so I have a solution for the problem above:

sudo apt-get install pciutils
sudo setpci -s 01:00.0 0xD4.B=0x41

This will resolve the issue of lagg and key sticking on usb devices (when using a usb webcam).

explaination (from https://linux.die.net/man/8/setpci):
-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]

with the tool setpci we write a byte (B) with the value '0x41' to register '0xD4'.
we write to:
domain: 01, bus: 00, slot: 0

I dont know why this value and register, I hope someone can answer that for me.

In my case it resolved the usb lagg & key sticking 100%.
there is a related update, but that didn't fix it for me: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=260879

cr (cr-newton) on 2020-01-06
description: updated
cr (cr-newton) on 2020-01-15
Changed in raspbian:
status: New → In Progress
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers