Git Product home page Git Product logo

picamera2's People

Contributors

6by9 avatar aallan avatar amudtogal avatar cdcformatc avatar chrisruk avatar corvettecole avatar davidplowman avatar ghollingworth avatar gkyle avatar grega avatar iantblack avatar ibmua avatar jenyak avatar jlprojects avatar luraminaki avatar mbradhoo avatar meawoppl avatar naushir avatar njhollinghurst avatar petros626 avatar schoolpost avatar steveiliop56 avatar tianrking avatar tvoverbeek avatar vincent-stragier avatar will-v-pi avatar zanz2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

picamera2's Issues

[BUG] Image scaling is abnormal

The runing:
self.picam2 = picamera2.Picamera2()
self.picam2.configure(self.picam2.preview_configuration({"size": (1536, 896)}))
self.picam2.start_preview(Preview.NULL)
self.picam2.start()
....
frame = self._webcam.picam2.capture_array()
if frame is None:
return
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
cv2.imshow("Camera", frame)

Both are multiples of 64 (1536, 896)
Then the final image gets only the reduced part.. not all full screen

[BUG] pip install picamera2 ignores NOGUI flag

Describe the bug
When trying to install picamera2 via pip without GUI components, I entered the command exactly as indicated in the instructions:

NOGUI=1 pip install picamera2

but the procedure still tries to install PyQt5, which results in the entire process hanging and being killed by the OS.

Collecting PyQt5
  Using cached PyQt5-5.15.7.tar.gz (3.2 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... \ Killed

which means picamera2 is never installed.

To Reproduce
See above.

Expected behaviour
I'd expect PyQt5 not to be installed at all, given the presence of the NOGUI=1 flag.

Console Output, Screenshots
Screen Shot 2022-06-28 at 2 28 19 PM

Hardware :
I am using a Raspberry Pi 3B+ with a Camera Module V2 NoIR attached. I'm running Debian GNU/Linux 11 (bullseye) aarch64.

Additional context
I don't know if this is relevant, but you'll notice from the screenshot that I have set up a conda/mamba environment (micromamba, specifically). The only relevant packages installed via conda that are being used in the picamera2 installation process are python, pip, and numpy; everything else was pip or apt installed as per the instructions. I don't know if this could potentially cause conflicts--the one in particular I'm concerned with is the fact that OpenCV was installed via apt, but can be imported in the base environment without issues--but I don't really see how it would cause the wheels to ignore the NOGUI flag.

I saw that #124 seemed to have done exactly this in making PyQt optional, but I can't seem to get that behavior to work.

[BUG] ... wrong import in app_capture_request.py

Installed picamera2-0.2.1; when running "app_capture_request.py", I got the following error

>>> %Run app_capture_request.py
Traceback (most recent call last):
  File "/home/pi/picamera2/examples/app_capture_request.py", line 10, in <module>
    from picamera2.previews import QPicamera2
ImportError: cannot import name 'QPicamera2' from 'picamera2.previews' (/usr/local/lib/python3.9/dist-packages/picamera2/previews/__init__.py)

It works if line 10 is changed from
picamera2.previews import QPicamera2
to
picamera2.previews.qt import QPicamera2

[HOW-TO] ExposureTime / ShutterSpeed

How set minimum ExposureTime / maximum ShutterSpeed.

Dear Developers, I working on a SkyCam for SolarPowerPredictions. I created some examples..

libcamera-jpeg -o shutterspeedxy.jpg --shutter xy

shutters

Ironically there comes a point where the exposure increases again instead of continuing to decrease.

However I just would like to reduce the exposure time further? How can I set the maximum possible, do i need to add more settings?

Thank you!

RFC: Personal Hit List

I am excited to contribute a fair bit of effort to getting this repository into more usable state. I currently rely on it for my day-job, and I am eager to make it better.

Here is the list of things, in rough order of my perceived importance, that I was thinking to work on:

  • Turning this repository into a more normally structured python package
  • Get the resource cleanup strategy under control. Review __del__ vs atexit approaches and bring them toward more idiomatic Python.
  • Document what is needed for the various preview interfaces (I am mainly interested in headless operations, so I will need help here)
  • Make some dependency installer scripts/support
  • Get the package up on pypi.
  • Start working on a backward compatibility wrapper - Filling the feature gaps between this and the original picamera module.

Some more stuff that has come up:

  • Get the testing into a standardized state

Potential modification to build instructions in README.md

In the commands following "Next we need some DRM/KMS bindings:"

I assume there's a missing "sudo ninja -C build install" at the end.

It might also be worth adding a note at the start to tell people not to try building on a RPi Zero W (as I did) as it hangs doing something swap related during this section of the build (it worked on a RPi 3 fwiw)

[BUG] Unable to re-open/start camera once stop or close is called

Describe the bug
I am unable to cleanly stop or close the camera connection. Once I do any combination of stop or close, I get an error on subsequent opens. I have to reboot in order to recover.

To Reproduce

Below is a slimmed down version based on the capture_headless.py example:

from picamera2 import Picamera2

picam2 = Picamera2()
config = picam2.still_configuration()
picam2.configure(config)

picam2.start() 
picam2.capture_file("demo1.jpg")
picam2.stop()

picam2.start() # <- This will raise an exception
picam2.capture_file("demo2.jpg")
picam2.stop()

Expected behaviour
To cleanly stop and close camera connection.

Console Output, Screenshots

Below I've included the stack trace. If I try to restart Python and create new Picamera instance I get a similar error when trying to configure ( picam2.configure(config) ) getting error ERROR RPI raspberrypi.cpp:873 Failed to set format on ISP Output1: -22. It seems like comm. to the camera isn't working?

[0:06:31.111655590] [74]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3544-22656360
[0:06:31.145453871] [92]  WARN CameraSensorProperties camera_sensor_properties.cpp:163 No static properties available for 'imx477'
[0:06:31.145495092] [92]  WARN CameraSensorProperties camera_sensor_properties.cpp:165 Please consider updating the camera sensor properties database
[0:06:31.145516166] [92] ERROR CameraSensor camera_sensor.cpp:591 'imx477 10-001a': Camera sensor does not support test pattern modes.
[0:06:31.172111369] [92]  INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/i2c@1/imx477@1a to Unicam device /dev/media0 and ISP device /dev/media1
[0:06:31.176780565] [74]  INFO Camera camera.cpp:1029 configuring streams: (0) 4032x3040-BGR888
[0:06:31.177196113] [92]  INFO RPI raspberrypi.cpp:760 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-pBCC
[0:06:33.696041744] [92] ERROR V4L2 v4l2_videodevice.cpp:1852 /dev/video15[70:cap]: Failed to start streaming: Invalid argument
2022-05-20T19:46:55.308Z | ERROR    | Camera did not start properly.
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [2], in <cell line: 9>()
      6 picam2.capture_file("demo1.jpg")
      7 picam2.stop()
----> 9 picam2.start()
     10 picam2.capture_file("demo2.jpg")
     11 picam2.stop()

File /usr/local/lib/python3.9/dist-packages/picamera2/picamera2.py:570, in Picamera2.start(self, event_loop)
    568 if event_loop and not self.have_event_loop:
    569     self.start_preview(Preview.NULL)
--> 570 self.start_()

File /usr/local/lib/python3.9/dist-packages/picamera2/picamera2.py:551, in Picamera2.start_(self)
    549 else:
    550     self.log.error("Camera did not start properly.")
--> 551     raise RuntimeError("Camera did not start properly.")

RuntimeError: Camera did not start properly.

Hardware :
Raspberry Pi 4 B w/ 8GB connected to Raspberry HQ Camera (IMX477).

Worth adding custom EXIF to capture_file?

I would like to write some additional EXIF tags to the captured .jpg file (specifically GEO - lat/long etc from a GPS, and possibly some other arbiary notes etc), rather than writing the jpeg, then having to add the data afterwards.

Of course, could just grab a raw image (with make_image) and then write the file, but as the library already has the capture_file method, wondering if would be interest in adding support for writing arbitrary EXIF data? Seems would be a common use case, and would avoid users having to duplicate the code in CompletedRequest.save()

Propose to extend the save() method, something like:

def save(self, name, filename, exif_dict={})
...
# add some extra tags to the user supplied data
exif_dict["0th"][piexif.ImageIFD.Make] = "Raspberry Pi"
...
exif_dict["Exif"][piexif.ExifIFD.ISOSpeedRatings] = int(total_gain * 100)
exif = piexif.dump(exif_dict)

and of course add to capture_file() (and capture_file_) so the data is passed though

Just unsure if would add before/after signal_function, suspect before, (because most users won't use signal_function)
def capture_file(self, filename, name="main", wait=True, exif_dict={}, signal_function=signal_event):

Then users would

gps_ifd = {
        piexif.GPSIFD.GPSVersionID: (2, 0, 0, 0),
        #...
}
exif_dict = {"GPS": gps_ifd}
picam2.capture_file("test.jpg", exif_dict = exif)

(above code is just proposal, not tested yet!)

I'd be willing to do this as a PR. Just checking if this the right direction first.

RuntimeError: Control 'DigitalGain' not found

When trying to set analog-, digitalgain and exposure with the following script:

#!/usr/bin/python3

from picamera2 import Picamera2, Preview
import time

picam2 = Picamera2()
picam2.start_preview(Preview.QT)

preview_config = picam2.preview_configuration()
picam2.configure(preview_config)

picam2.start()
time.sleep(1)
metadata = picam2.capture_metadata()
print(metadata)

time.sleep(1)
controls = {}
controls['AnalogueGain'] = 1.0
controls['DigitalGain']  = 2.0
controls['ExposureTime'] = 3000

print(controls)
picam2.set_controls(controls)
time.sleep(1)
metadata = picam2.capture_metadata()
print(metadata)
time.sleep(5)

I get the error "RuntimeError: Control 'DigitalGain' not found". When commenting out line 20, controls['DigitalGain'] = 2.0, everthing works as expected. I am using a HQ camera attached to a PI 3; setting both gains was no problem in the original picamera-library. The opencv_mertens_merge.py uses only AnalogueGain - is setting DigitalGain something libcamera does not allow for?

flash_mode

Hello,

With the previous version I used "flash_mode" on with a LED to use it as a flash; How can I do it now ?

Thanks !

HQ Camera does not start at full resolution.

With a Raspberry Pi Zero 2 W running Buster 32bit and an HQ Camera this is the code I am using:

from picamera2.picamera2 import *
import time

picam2 = Picamera2()
picam2.start_preview()

config = picam2.still_configuration()
picam2.configure(config)

picam2.start()

time.sleep(2)

image = picam2.capture_file("test.jpg")

picam2.stop()

and this is the output:

[0:39:01.109655276] [2255]  INFO IPAManager ipa_manager.cpp:138 libcamera is not installed. Adding '/home/pi/dev/libcamera/build/src/ipa' to the IPA search path
[0:39:01.118175912] [2255]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3447-c6bb050a
[0:39:01.125627732] [2256]  WARN CameraSensorProperties camera_sensor_properties.cpp:141 No static properties available for 'imx477'
[0:39:01.125736276] [2256]  WARN CameraSensorProperties camera_sensor_properties.cpp:143 Please consider updating the camera sensor properties database
[0:39:01.125803985] [2256] ERROR CameraSensor camera_sensor.cpp:551 'imx477 10-001a': Camera sensor does not support test pattern modes.
[0:39:01.160112315] [2256]  INFO IPAProxy ipa_proxy.cpp:130 libcamera is not installed. Loading IPA configuration from '/home/pi/dev/libcamera/src/ipa/raspberrypi/data'
[0:39:01.195346075] [2256]  INFO RPI raspberrypi.cpp:1337 Registered camera /base/soc/i2c0mux/i2c@1/imx477@1a to Unicam device /dev/media2 and ISP device /dev/media0
2022-03-20T05:57:15.885Z | INFO     | Initialization successful.
2022-03-20T05:57:15.885Z | INFO     | Camera now open.
[0:39:01.204407916] [2255]  INFO Camera camera.cpp:1028 configuring streams: (0) 4048x3040-XBGR8888
[0:39:01.206843627] [2256]  INFO RPI raspberrypi.cpp:757 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-pBCC
2022-03-20T05:57:15.897Z | INFO     | Configuration successful!
[0:39:02.882906289] [2256] ERROR V4L2 v4l2_videodevice.cpp:1192 /dev/video14[15:cap]: Unable to request 1 buffers: Cannot allocate memory
[0:39:02.944480300] [2256] ERROR RPI raspberrypi.cpp:999 Failed to allocate buffers
2022-03-20T05:57:17.906Z | ERROR    | Camera did not start properly.
Traceback (most recent call last):
  File "/home/pi/dev/volcapcam/picamtest.py", line 10, in <module>
    picam2.start()
  File "/home/pi/dev/picamera2/picamera2/picamera2.py", line 491, in start
    self.start_(controls)
  File "/home/pi/dev/picamera2/picamera2/picamera2.py", line 485, in start_
    raise RuntimeError("Camera did not start properly.")
RuntimeError: Camera did not start properly.

Increasing the buffer size at full resolution to 3 or greater:
config = picam2.still_configuration(buffer_count=3)

Causes a different error:

[0:48:04.453514304] [2425]  INFO IPAManager ipa_manager.cpp:138 libcamera is not installed. Adding '/home/pi/dev/libcamera/build/src/ipa' to the IPA search path
[0:48:04.455952083] [2425]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3447-c6bb050a
[0:48:04.462834844] [2426]  WARN CameraSensorProperties camera_sensor_properties.cpp:141 No static properties available for 'imx477'
[0:48:04.462945158] [2426]  WARN CameraSensorProperties camera_sensor_properties.cpp:143 Please consider updating the camera sensor properties database
[0:48:04.463012554] [2426] ERROR CameraSensor camera_sensor.cpp:551 'imx477 10-001a': Camera sensor does not support test pattern modes.
[0:48:04.491360845] [2426]  INFO IPAProxy ipa_proxy.cpp:130 libcamera is not installed. Loading IPA configuration from '/home/pi/dev/libcamera/src/ipa/raspberrypi/data'
[0:48:04.526177104] [2426]  INFO RPI raspberrypi.cpp:1337 Registered camera /base/soc/i2c0mux/i2c@1/imx477@1a to Unicam device /dev/media2 and ISP device /dev/media0
2022-03-20T06:06:19.216Z | INFO     | Initialization successful.
2022-03-20T06:06:19.216Z | INFO     | Camera now open.
[0:48:04.533299138] [2425]  INFO Camera camera.cpp:1028 configuring streams: (0) 4048x3040-XBGR8888
[0:48:04.534249249] [2426]  INFO RPI raspberrypi.cpp:757 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-pBCC
2022-03-20T06:06:19.224Z | INFO     | Configuration successful!
[0:48:04.851581019] [2426] ERROR V4L2 v4l2_videodevice.cpp:1199 /dev/video14[15:cap]: Not enough buffers provided by V4L2VideoDevice
Traceback (most recent call last):
  File "/home/pi/dev/volcapcam/picamtest.py", line 8, in <module>
    picam2.configure(config)
  File "/home/pi/dev/picamera2/picamera2/picamera2.py", line 458, in configure
    self.configure_(camera_config)
  File "/home/pi/dev/picamera2/picamera2/picamera2.py", line 447, in configure_
    self.logger.critical("Failed to allocate buffers.")
AttributeError: 'Picamera2' object has no attribute 'logger'

Lowering the resolution by half works:
config = picam2.still_configuration(main={"size": (2028, 1520)})

Preview configuration also works at half resolution:
config = picam2.preview_configuration(main={"size": (2028, 1520)})

But a preview configuration at full resolution results in the same Not enough buffers provided by V4L2VideoDevice error:
config = picam2.preview_configuration(main={"size": (4056, 3040)})

[HOW-TO] How to use the autofocus control

Describe what it is that you want to accomplish
How to use the autofocus control.

Describe alternatives you've considered
In your C++ libcamera library, I remember that it supports autofocus control๏ผˆAfTrigger๏ผ‰, but I can't find this control in the picamera2 packaged by it, can you tell me his name?

Additional context
ssss

Qt widget based camera crashes after taking some stills

Hi,

I expirianced some crashes with Qt widget based camera preview (q_gl_picamera2) taking stills with switch_mode_and_capture_file.
Long terms short, I'm able to replicate the chrashes after taking some stills in the example "app_capture.py" too. Simply take some stills repeatedly and it will crash at around ten pics (at me the first try 8 times, the second try 13 times).
The error displayed will be: Camera did not start properly.

v4l2 module missing in installation instructions

With the addition of the video files, picamera2.py now imports encoder.py which in turn imports v4l2.
However python module v4l2 is not available in apt (at least I could not find it).
There is a v4l2 python module on Pypi.
Is that the one we need?

[BUG] Cannot allocate memory after capture_request() and release()

Describe the bug
Repeated calls to capture_request() prompt this V4L2 error:

ERROR V4L2 v4l2_videodevice.cpp:1211 /dev/video14[16:cap]: Unable to request 1 buffers: Cannot allocate memory
ERROR RPI raspberrypi.cpp:1008 Failed to allocate buffers
ERROR | Camera did not start properly.

To Reproduce
Here is a short test case. If I make repeated calls to switch_mode_and_capture_image(), I can capture stills indefinitely. When I use switch_mode() and capture_request(), the V4L2 error occurs after 4 or 5 iterations.

from picamera2 import Picamera2, Preview
import time

camera = Picamera2()
camera.start_preview(Preview.DRM)
preview_config = camera.preview_configuration()
capture_config = camera.still_configuration(raw={})
camera.configure(preview_config)

def capture_img():
    pilImage = camera.switch_mode_and_capture_image(capture_config)
    print(pilImage)

def capture_req():
    camera.switch_mode(capture_config)
    request = camera.capture_request()
    pilImage = request.make_image("main")
    print(pilImage)
    request.release()

camera.start()

while True:
    capture_req()
    time.sleep(2)

camera.close()

Expected behaviour
Memory should be freed by CompletedRequest.release().

Hardware :
Compute Module 4 w/ 256MB allocated to GPU. PiCam HQ

[BUG]opencv_mertens_merge.py is not working.

With the current version of Picamera2 (0.2.2) when I try to run the opencv_mertens_merge.py script the three images created appear to be the same. It seems like setting the "ExposureTime" is not having any effect.

To reproduce,
Install the current release version of libcamera.
Install the latest version of picamera2 from git
Edit the script to output the three intermediate images - I added these three lines

cv2.imwrite("normal.jpg", normal)
cv2.imwrite("short.jpg", short)
cv2.imwrite("long.jpg", long)

The images should be different but they are visually the same.

I am running on a 4GB Pi4 using Bullseye with an imx477 camera
It may not be relevant but the config.txt includes:
dtoverlay=vc4-fkms-v3d
Rather than the default:
dtoverlay=vc4-kms-v3d

With the default, when I disabled legacy camera support and performed the required reboot the HDMI port would be disabled. So effectively enabling LibCamera disabled HDMI. If I moved the SD card to a Pi3 then they would both work.

I've tried running the script on a Pi3 with the same result.

Thanks in advance
Tim

[BUG] trying to access video stream through capture_stream.py results in Broken Pipe

Describe the bug
Running the capture_stream.py and accessing it through e.g. VLC Media Player or jsmpeg results in Broken Pipe error.
Accessing through browser works.

To Reproduce
I'm accessing my Pi from my main pc, and need the stream there, so I adjusted the ip among other things, but all round it should still work the same, At least I get the same result when using the standard script.

import socket
import time

from picamera2.encoders import H264Encoder
from picamera2.outputs import FileOutput
from picamera2 import Picamera2

try:
    picam2 = Picamera2()
    video_config = picam2.video_configuration({"size": (1280, 720)})
    picam2.configure(video_config)
    picam2.encoder = H264Encoder(1000000, False)
    picam2.start()

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
        # sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        # localhost of the raspberry
        # sock.bind(("0.0.0.0", 10001))
        # address accessible to workstation
        sock.bind(("10.42.0.2", 10001))
        sock.listen(5)

        conn, addr = sock.accept()
        print(f"connection accepted, addr: {addr}, conn: {conn}")

        stream = conn.makefile("wb")
        picam2.encoder.output = FileOutput(stream)
        picam2.start_encoder()
        # picam2.start()

        print(sock.getsockname())
        time.sleep(60)
        # while True:
        #     time.sleep(1)

        picam2.stop()
        picam2.stop_encoder()
        conn.close()
        exit(0)

except Exception as e:
    print(f"\nError occured: {e}\n")

Expected behaviour
I expect for the videostream to appear.

Console Output, Screenshots

BrokenPipeError: [Errno 32] Broken pipeException in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/home/poncha_pi/.local/lib/python3.9/site-packages/picamera2/encoders/v4l2_encoder.py", line 173, in thread_poll
    self.output.outputframe(b, keyframe)
  File "/home/poncha_pi/.local/lib/python3.9/site-packages/picamera2/outputs/fileoutput.py", line 36, in outputframe
    self._fileoutput.write(frame)
  File "/usr/lib/python3.9/socket.py", line 722, in write
    return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe

Hardware :
I'm using a Pi 4B and a v2 Camera.

No "sport" exposure mode

Hello,

thanks for your great work! I want to use the pi cam hq with the shortest shutter time possible.
Is there any way to activate the sports exposure mode with picamera2?
This is from the libcamera -help output:
'--exposure arg (=normal) Set the exposure mode (normal, sport)'

Couldn't find this option in picamera2 but maybe I missed something.

Thanks in advance
Felix

What configuration for IP Camera frame flow

I'm developing a Raspberry PI 4-based IM477 IP camera using Picamera2.
The Raspberry has a thread that continues to get frame image and encode it to JPEG.
A socket receives the GRAB command and the current threaded acquired frame is sent back to the consumer client.
The frame resolution and camera start are managed between a START_CAMERA TCP command before requesting GRAB.

Now the question.
For a continuous frame get to Picamera2 what is the best configuration way?

Preview or Still or something other?
What I want is the fastest way to get continuous frames JPEG-Encoded to be shown in a Windows program that uses
OpenCV to elaborate frame flow and show it on screen (as a video).

A moment I've used:

 self.__camera.configure(self.__camera.preview_configuration(main={"format": 'RGB888', "size": (camera_width, camera_height)}))
 self.__camera.start()
 self.__camera_controls = CAMERA_CONTROLS_DEFAULT
 self.__frame_acquire_thread_exit_event = threading.Event()
 self.__frame_acquire_thread = threading.Thread(target=self.__frame_acquire_thread_main, args=(None,))
 self.__frame_acquire_thread.start()
    # == BEG: frame acquire thread implementation
    #
    def __frame_acquire_thread_main(self, args):
        while not self.__frame_acquire_thread_exit_event.is_set():
            #time.sleep(0.0001)
            try:
                frame = self.__camera.capture_array()
                if frame is None:
                    continue
                if IMAGE_ENCODE_WITH_SJPEG:
                    frame_enc = np.frombuffer(sjpeg.encode_jpeg(frame, quality=IMAGE_ENCODE_SJPEG_RATIO, colorspace='BGR', fastdct=IMAGE_ENCODE_SJPEG_FASTDCT), dtype=np.ubyte)
                else:
                    _, frame_enc = cv2.imencode(IMAGE_ENCODE_FORMAT, frame, IMAGE_ENCODE_FLAGS)
                self.__frame = frame_enc.copy()
                self.__frame_acquire_count += 1
            except:
                pass

    #
    # == END: frame acquire main thread implementation

There is a way with Picamera2 to choose the UNICAM camera sensor format?
At moment, for example, with the main preview width:height 640x480 Picamera2 uses a larger UNICAM format where IMX477 support also 640:480.

No named AwbModes

I would like to use the AWB mode names as defined in the libcamera documentation: auto, incandescent, tungsten, etc.
However only numeric values 0-7 are allowed now.
This is similar to #38 for exposure mode.

[BUG] Can't import picamera2.

Describe the bug
When I install dependencies on a card that has been used for a while, there will be a problem of not being able to import picamera2.

To Reproduce
https://github.com/raspberrypi/picamera2 According to the github README.md tutorial

Expected behaviour
I can't use picamera2, but whenever the system is reflashed, and executed again, it works fine. I'm 100% sure their environments are the same because I've been using the same thing.

Console Output, Screenshots
nnnn

Hardware :
pi4(c03112) + 2022-04-07 bulleye armf + imx477

Dependency to PyQt

Do you plan to propose a headless version of picamera2, without the dependency on PyQt which is only necessary for previews (if I understand correctly)?

Full resolution encoding doesn't work for camera v2

#!/usr/bin/python3

from picamera2.encoders.h264_encoder import *
from picamera2.picamera2 import *
import time
import os

picam2 = Picamera2()
video_config = picam2.video_configuration({'size':picam2.sensor_resolution})
picam2.configure(video_config)

picam2.start_preview()
encoder = H264Encoder(10000000)

picam2.start_recording(encoder, 'test.h264')
time.sleep(10)
picam2.stop_recording()

gives the output

[0:01:59.761992574] [1703]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3447-c6bb050a
[0:01:59.770978897] [1704]  INFO IPAProxy ipa_proxy.cpp:130 libcamera is not installed. Loading IPA configuration from '/home/pi/libcamera/src/ipa/raspberrypi/data'
[0:01:59.785928705] [1704]  WARN RPI raspberrypi.cpp:1222 Mismatch between Unicam and CamHelper for embedded data usage!
[0:01:59.786501034] [1704]  INFO RPI raspberrypi.cpp:1337 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media3 and ISP device /dev/media1
2022-03-21T15:51:31.784Z | INFO     | Initialization successful.
2022-03-21T15:51:31.786Z | INFO     | Camera now open.
[0:01:59.790679252] [1703]  INFO Camera camera.cpp:1028 configuring streams: (0) 3280x2464-XBGR8888
[0:01:59.791085052] [1704]  INFO RPI raspberrypi.cpp:757 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 3280x2464-SBGGR10_1X10 - Selected unicam format: 3280x2464-pBAA
2022-03-21T15:51:31.794Z | INFO     | Configuration successful!
Traceback (most recent call last):
  File "/home/pi/projects/Telescope/scratch.py", line 15, in <module>
    picam2.start_recording(encoder, 'test.h264')
  File "/home/pi/picamera2/picamera2/picamera2.py", line 856, in start_recording
    self.start_encoder()
  File "/home/pi/picamera2/picamera2/picamera2.py", line 834, in start_encoder
    self.encoder._start()
  File "/home/pi/picamera2/picamera2/encoders/h264_encoder.py", line 97, in _start
    fcntl.ioctl(self.vd, VIDIOC_STREAMON, typev)
ProcessLookupError: [Errno 3] No such process

H.264 obviously has some issues with 4k encoding, but my understanding is that it should be possible.

[BUG] Current Distribution does not match Github

I recently installed picamera2 on my Pi and I am trying to learn the package by using the examples.

I discovered that the post_callback requests were not firing. I reviewed the code on my Mac and could not find the error. So I decided to try and debug on my Pi. I opened picamera2.py on the Pi only to discover post_callback does not exist instead the variable is request_callback.

My plan is to uninstall the distribution and clone the github version to the Pi but thought you would want to know.

Note: When I uninstalled the Version was pycamera2-0.2.1

[HOW-TO] Set multiple parameters to video_configuration?

Hello!

I'm just starting to try and use the picamera2 python packages.
First things is I wanted to try and configure a 720p60 h264 recording and also save out the timestamps.

Like this commandline does,
libcamera-vid -t 10000 --width 1280 --height 720 --framerate 60 --intra 10 -b 40000000 -o test.h264 --save-pts timestamps.txt

I can't find any examples that sets multiple parameters to the recording.

I just tried this and it doesn't error but ffprobe reports 30fps.

video_config = picam2.video_configuration({"size": (1280, 720), "FrameDurationLimits": (16666, 33333)}) # 1000000 / 60

also tried,
picam2.set_controls({"FrameDurationLimits": (16666, 33333)})

Any help with this would be amazing or if there's a example code somewhere to look at?

Cheers!

capture_jpeg.py: numpy.ndarray size change.. Expected 48, got 40

Running capture_jpeg.py throws exception:

$ ./capture_jpeg.py 
Traceback (most recent call last):
  File "/home/pi/Pi4BE32/Examples/picamera2/./capture_jpeg.py", line 6, in <module>
    from picamera2 import Picamera2, Preview
  File "/home/pi/picamera2/picamera2/__init__.py", line 1, in <module>
    from .picamera2 import Picamera2, Preview
  File "/home/pi/picamera2/picamera2/picamera2.py", line 14, in <module>
    from picamera2.encoders import Encoder
  File "/home/pi/picamera2/picamera2/encoders/__init__.py", line 3, in <module>
    from .jpeg_encoder import JpegEncoder
  File "/home/pi/picamera2/picamera2/encoders/jpeg_encoder.py", line 1, in <module>
    import simplejpeg
  File "/usr/local/lib/python3.9/dist-packages/simplejpeg/__init__.py", line 1, in <module>
    from ._jpeg import encode_jpeg
  File "simplejpeg/_jpeg.pyx", line 1, in init simplejpeg._jpeg
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 48 from C header, got 40 from PyObject

PiOS Bullseye 32-bit: Linux Pi4BE32 5.15.32-v7l+ #1538 SMP Thu Mar 31 19:39:41 BST 2022 armv7l GNU/Linux
Python 3.9.2
python3-libcamera/stable,now 0~git20220510+22656360-1 armhf [installed]
v4l2-python3==0.3.1

$ libcamera-jpeg --list
[0:04:16.510502904] [975]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3544-22656360
[0:04:16.526498464] [976] ERROR CameraSensor camera_sensor.cpp:591 'ov5647 10-0036': Camera sensor does not support test pattern modes.
[0:04:16.543963437] [976]  INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media3 and ISP device /dev/media0
Available cameras
-----------------
0 : ov5647 [2592x1944] (/base/soc/i2c0mux/i2c@1/ov5647@36)
    Modes: 'SGBRG10_CSI2P' : 640x480 1296x972 1920x1080 2592x1944 

Tried both with numpy version 1.19.5 (sudo apt install python3-numpy) and version 1.22.3 (pip3 install numpy)

Make q_picamera2 and q_gl_picamera2 dynamic size

I think the camera preview in the q_picamera2 and q_gl_picamera2 should be made (optionally) to automatically fill the size of its container. This problem can be seen in examples/app_capture.py - resizing or maximising the window doesn't look very good. The preview in many application cases I'd expect will need to fit the maximum space available.

My project is a cine film scanner using the HQ camera. It's original control UI was written using picamera and tkinter which sort of worked, but very clunky. I decided to start again using picamera2 and PyQt5, so I'm fumbling to implement a new GUI.
The q_picamera2 and q_gl_picamera2 widget looks ideal for showing a live view for focussing and aligning the camera, and indeed I'm starting by building on app_capture.py for a live preview and basic camera settings.

I altered q_picamera2.py to implement a dynamic resize which seems to work - patch below. It implements a resize event, decouples the camera image size from the label size, centres the camera image in the label. A layout control fills the label to the size of the parent widget. The overlay is handled and resized as necessary. It can be tested in examples/app_capture.py by replacing theq_glpicamera2.py import to q_picamera2 and the qpicamera2 declaration to qpicamera2 = QPicamera2(picam2,resizeable=True)

I'm sure it can be optimised. Similar functionality should exist on the GL preview widget but I got lost trying to understand the GL code. Just getting up to speed with basic PyQt at the moment.

--- q_picamera2.py.orig	2022-04-10 09:53:31.931882445 +0100
+++ q_picamera2.py	2022-04-10 11:10:19.290102418 +0100
@@ -1,17 +1,29 @@
 from PyQt5 import QtCore, QtGui, QtWidgets
 from PyQt5.QtCore import pyqtSlot, QSocketNotifier
-from PyQt5.QtWidgets import QWidget, QApplication, QLabel
+from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QVBoxLayout
 from PIL import Image
 from PIL.ImageQt import ImageQt
 import numpy as np
 
 
 class QPicamera2(QWidget):
-    def __init__(self, picam2, parent=None, width=640, height=480):
+    def __init__(self, picam2, parent=None, width=640, height=480, resizeable=False):
         super().__init__(parent=parent)
         self.picamera2 = picam2
+        self.image_ratio = height / width
+        self.img_size = QtCore.QSize(width, height)
         self.label = QLabel(self)
-        self.label.resize(width, height)
+        self.label.setAlignment(QtCore.Qt.AlignCenter)
+        self.label.setMinimumWidth(80)
+        self.label.setMinimumHeight(60)
+        self.resizeable = resizeable
+        if resizeable:
+            self.vbox = QVBoxLayout()
+            self.vbox.addWidget(self.label)
+            self.setLayout(self.vbox)
+        else:
+            self.label.resize(width, height)
+        self.overlay_orig = None
         self.overlay = None
         self.painter = QtGui.QPainter()
         self.camera_notifier = QSocketNotifier(self.picamera2.camera_manager.efd,
@@ -19,17 +31,31 @@
                                                self)
         self.camera_notifier.activated.connect(self.handle_requests)
 
+    def resizeEvent(self, event):
+        if not self.resizeable: return
+        # Keep aspect ratio
+        size = event.size()
+        width,height = size.width(),size.height()
+        new_width, new_height = width, int(width*self.image_ratio)
+        if new_height > height:
+            # Fit to height
+            new_width, new_height = int(height/self.image_ratio), height
+        self.img_size = QtCore.QSize(new_width,new_height)
+        if self.overlay is not None:
+            # Resize overlay
+            self.overlay = self.overlay_orig.scaled(self.img_size)
+        
     def set_overlay(self, overlay):
         if overlay is not None:
             # Better to resize the overlay here rather than in the rendering loop.
-            orig = overlay
             overlay = np.ascontiguousarray(overlay)
             shape = overlay.shape
-            size = self.label.size()
-            if orig is overlay and shape[1] == size.width() and shape[0] == size.height():
+            size = self.img_size
+            if self.overlay_orig is overlay and shape[1] == size.width() and shape[0] == size.height():
                 # We must be sure to copy the data even when no one else does!
                 overlay = overlay.copy()
             overlay = QtGui.QImage(overlay.data, shape[1], shape[0], QtGui.QImage.Format_RGBA8888)
+            self.overlay_orig = overlay.copy()
             if overlay.size() != self.label.size():
                 overlay = overlay.scaled(self.label.size())
 
@@ -43,7 +69,7 @@
 
         if self.picamera2.display_stream_name is not None:
             # This all seems horribly expensive. Pull request welcome if you know a better way!
-            size = self.label.size()
+            size = self.img_size
             img = request.make_image(self.picamera2.display_stream_name, size.width(), size.height())
             qim = ImageQt(img)
             self.painter.begin(qim)

[OTHER] Resolution 4032x3040

#!/usr/bin/python3

 # Capture a DNG and a JPEG made from the same raw data.

from picamera2 import Picamera2, Preview
import time

picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)

preview_config = picam2.preview_configuration()
capture_config = picam2.still_configuration(raw={}, display=None)
picam2.configure(preview_config)

picam2.start()
time.sleep(2)

r = picam2.switch_mode_capture_request_and_stop(capture_config)
r.save(name="main", filename="full.jpg")
r.save_dng(filename="full.dng")

1. Is it possible to capture images without using preview?
2. Why do I get 4032x3040, I should get 4056x3040

Wi-Fi is currently blocked by rfkill.
Use raspi-config to set the country before use.

[0:12:20.526728361] [2812]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3544-22656360
[0:12:20.543309989] [2813]  WARN CameraSensorProperties camera_sensor_properties.cpp:163 No static properties available for 'imx477'
[0:12:20.543356229] [2813]  WARN CameraSensorProperties camera_sensor_properties.cpp:165 Please consider updating the camera sensor properties database
[0:12:20.543386377] [2813] ERROR CameraSensor camera_sensor.cpp:591 'imx477 10-001a': Camera sensor does not support test pattern modes.
[0:12:20.559965264] [2813]  INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/i2c@1/imx477@1a to Unicam device /dev/media0 and ISP device /dev/media1
[0:12:22.053185534] [2812]  INFO Camera camera.cpp:1029 configuring streams: (0) 640x480-XBGR8888
[0:12:22.060285050] [2813]  INFO RPI raspberrypi.cpp:760 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 2028x1520-SBGGR12_1X12 - Selected unicam format: 2028x1520-pBCC
qt.qpa.xcb: QXcbConnection: XCB error: 148 (Unknown), sequence: 192, resource id: 0, major code: 140 (Unknown), minor code: 20
[0:12:25.042919247] [2816]  INFO Camera camera.cpp:1029 configuring streams: (0) 4032x3040-BGR888 (1) 4056x3040-SBGGR12_CSI2P
[0:12:25.045845856] [2813]  INFO RPI raspberrypi.cpp:760 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-pBCC

3. I use Ethernet and turned off wifi, what is this warning good for?
4. no static proberties available? sensor does not support test patters?

[BUG] Camera __init__ sequence did not complete

After installing picamera2 as suggested I also had to install libcamera from source (and thus kmsxx and all the dependencies).
I now have a working libcamera installation and all the cli commands provide images.

After trying the following code

from picamera2 import Picamera2, Preview

ppcam = Picamera2()
ppcam.start()

I have this

[0:07:42.544557834] [1455] INFO IPAManager ipa_manager.cpp:138 libcamera is not installed. Adding '/home/pi/libcamera/build/src/ipa' to the IPA search path
[0:07:42.545470529] [1455] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3630-d0b310b4
[0:07:42.554329995] [1459] INFO IPAProxy ipa_proxy.cpp:130 libcamera is not installed. Loading IPA configuration from '/home/pi/libcamera/src/ipa/raspberrypi/data'
[0:07:42.563849801] [1459] INFO RPI raspberrypi.cpp:1356 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media2 and ISP device /dev/media0
2022-06-09T10:41:06.356Z | ERROR | Camera init sequence did not complete.
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/picamera2.py", line 77, in init
self.open_camera()
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/picamera2.py", line 164, in open_camera
if self.initialize_camera():
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/picamera2.py", line 148, in initialize_camera
self.sensor_resolution = self.camera.properties["PixelArraySize"]
KeyError: 'PixelArraySize'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/cam.py", line 3, in
ppcam = Picamera2()
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/picamera2.py", line 81, in init
raise RuntimeError("Camera init sequence did not complete.")
RuntimeError: Camera init sequence did not complete.

I just don't know what to do, if anyone has any ideas I would be grateful ! Thanks

raw image functionality

  1. I found "raw.py" example works just fine.

picam2.capture_array("raw")

but, the result of this function was different from the result of the "picamera"

stream = io.BytesIO()
camera.capture(stream, format='jpeg', bayer=True)

It also contains metadata of raw stream.
In this way, you can easily process the raw stream by passing them to a raw decoder,
for example,

rawpy.imread(steram)

It would be nice if picamera2 also made a function that would do the same as above.

  1. Also, In the raw stream mode, the image saving function is different from the intended one.
config = picam2.preview_configuration(raw={"size": picam2.sensor_resolution})
preview = NullPreview(picam2)
picam2.configure(config)
picam2.start({"AwbMode": 6, "ExposureTime": 20000, "AnalogueGain": 1.0})
picam2.capture_file('test.jpg')

This does not save the raw stream, but the preview(640x480) image only.
I thought it would be saved the file like the following legacy method
(jpg+metadata+raw stream[after 'BCRM' string]).

raspistill -r -o 'test.jpg'

and the following command is not implemented and an error occurs.

picam2.capture_file('test.dng')

I thought it would be saved the file like the libcamera command.

libcamera-still -r -o test.dng

No module named 'libcamera'

Hello,

Thanks for your help; I'm sure that my doubt is because I'm a noob in raspberry, but I cannot find the answer googling it:

I'm using the latest version of raspbian 64 bits (Bullseye), installed two days ago...

I have followed all the installation steps for picamera2, and as far as I know, I had no problems.

I'm trying to test it with a simple .py , that only has a single line "import picamera2", but it complains that it cannot find module libcamera:

a2test1.py

Traceback (most recent call last):
File "/home/pi/PycharmProjects/FotoMoniTests/Picamera2 tests/picamera2test1.py", line 3, in
import picamera2
File "/home/pi/picamera2/picamera2.py", line 4, in
import libcamera
ModuleNotFoundError: No module named 'libcamera'

I don't know where libcamera is located, but I think it is on the system, because its tools are working correctly (for example, libcamera-hello shows the preview).

Thanks in advance,

Roger

OpenCV 64-Bit install Script

I saw your request in the readme, so I though I would share this recipe:

#!/bin/bash

# Requires the following apt packages to be installed:
# build-essential cmake git unzip pkg-config            \
# libjpeg-dev libtiff-dev libpng-dev libavcodec-dev libavformat-dev      \
# libswscale-dev libgtk2.0-dev libcanberra-gtk* libgtk-3-dev             \
# libgstreamer1.0-dev gstreamer1.0-gtk3 libgstreamer-plugins-base1.0-dev \
# gstreamer1.0-gl libxvidcore-dev libx264-dev python3-dev python3-numpy  \
# python3-pip libtbb2 libtbb-dev libdc1394-22-dev libv4l-dev v4l-utils   \
# libopenblas-dev libatlas-base-dev libblas-dev liblapack-dev gfortran   \
# libhdf5-dev libprotobuf-dev libgoogle-glog-dev libgflags-dev protobuf-compiler

set -e
echo "Installing OpenCV 4.5.5 on your Raspberry Pi 64-bit OS"
echo "This is going to take a while. Get a coffee/beer"
start_time=$(date +%s)

# download the latest version
cd ~
sudo rm -rf opencv*
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.5.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.5.zip

# unpack
unzip opencv.zip
unzip opencv_contrib.zip

# some administration to make live easier later on
mv opencv-4.5.5 opencv
mv opencv_contrib-4.5.5 opencv_contrib

# clean up the zip files
rm opencv.zip
rm opencv_contrib.zip

# set install dir
mkdir ~/opencv/build
cd ~/opencv/build

# run cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D WITH_OPENMP=ON \
-D WITH_OPENCL=OFF \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D WITH_GSTREAMER=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=OFF \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D WITH_VTK=OFF \
-D WITH_QT=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF ..

# run make
make -j4
sudo make install
sudo ldconfig

# cleaning (frees 300 MB)
make clean

echo "Congratulations!"
echo "You've successfully installed OpenCV 4.5.5 on your Raspberry Pi 64-bit OS"
end_time=$(date +%s)
elapsed=$(( end_time - start_time ))

eval "echo Elapsed time: $(date -ud "@$elapsed" +'$((%s/3600/24)) days %H hr %M min %S sec')"

This takes quite a number of hours to run . . .

RuntimeError: deque mutated during iteration in CircularOutput.py

Error raised when called from capture.circular.py example.

Error is inconsistent and usually occurs during a run of multiple motion triggers and captures.

Seems to be related to either size of mainstream video set up in capture.circular.py or to buffersize in circular.output.py .

As outlined in forum report some video size options seem more likely to trigger it than others.

Compatibility with previous PiCamera python library

I have projects that will need to be migrated and was hoping the picamera2 python syntax once initiated will be compatible with the picamera 1.13 library syntax and recipes. Can you provide some insight as to expected compatibility and how much effort can be expected to migrate a project or make existing projects cross compatible eg Buster and prior vs Bullseye and future.
Thanks

[HOW-TO] Change MJPEGserver.py to H.264

So I am relatively new to this streaming business, but I've been having struggles with fps and latency when using the mjpegserver.py file. Is there an easy way to increase to about 30 fps consistently or to change the format to use the h264 encoder? I'm basically just looking for any way to have a smoother stream over http.

[HOW-TO] get current value of Brightness, Contrast, etc

I'm using Raspberry Pi4 Bullseye with PiCamera2 (IMX219) which is used as a remote camera and receive commands
from TCP socket and send back frames using UDP to another computer.

I was able to change camera controls with TCP Commands using camera.set_controls() but I was not able to
understand how to retrieve the actual value for example of Brightness necessary to update a trackbar which
regulate the current value of Brightness, Contrast, and Sharpness.

`
def command_set_cap(data):

        def control_value_set(name, value):
            controls = {name: value}
            self.__camera.set_controls(controls)
            
        response = [ERROR]
        if len(data) == 9:
            cap_id = int_read(data, 1)
            cap_value = int_read(data, 5)
            if   cap_id == PROP_ID_BACKLIGHT:
                # TODO
            elif cap_id == PROP_ID_BRIGHTNESS:
                control_value_set('Brightness', cap_value / 100.0)
                response = [OK]
            elif cap_id == PROP_ID_CONTRAST:
                control_value_set('Contrast', cap_value * 2 / 100.0)
                response = [OK]
		...
		..
		.

`
Reading back camera.controls I can have ONLY the limits and default for needed camera options:

`
print(self.__camera.camera_controls)

{
'FrameDurationLimits': (1000, 1000000000, 0),
'ColourCorrectionMatrix': (-16.0, 16.0, 0),
'NoiseReductionMode': (0, 4, 0),
'Contrast': (0.0, 32.0, 1.0),
'AwbMode': (0, 7, 0),
'ScalerCrop': ((0, 0, 0, 0), (65535, 65535, 65535, 65535), (0, 0, 0, 0)),
'AwbEnable': (False, True, 0),
'ExposureValue': (-8.0, 8.0, 0.0),
'ColourGains': (0.0, 32.0, 0),
'AeExposureMode': (0, 3, 0),
'Sharpness': (0.0, 16.0, 1.0),
'Brightness': (-1.0, 1.0, 0.0),
'AeConstraintMode': (0, 3, 0),
'AeMeteringMode': (0, 3, 0),
'AnalogueGain': (1.0, 32.0, 0),
'Saturation': (0.0, 32.0, 1.0),
'ExposureTime': (0, 999999, 0),
'AeEnable': (False, True, 0)
}
`

FPS change, a lot, depending on object distance from camera

Describe the bug
FPS change, a lot, depending on object distance from the camera.
In the following video, you can see how the picam2.capture_array() slowdown when I change the object distance from the camera.
This does not happen with "libcamera-hello -t 0.

Screen capture of issue: https://youtu.be/-fcGAsdIHT4

To Reproduce
The used code is:

#!/usr/bin/python3

import time

import cv2
import numpy as np
from picamera2 import Picamera2

picam2 = Picamera2()
main = {"format": 'RGB888', "size": (640, 480)}
raw = {"format": "SRGGB10_CSI2P", "size": (1332, 990)}
config = picam2.preview_configuration(main, raw=raw)
picam2.configure(config)
picam2.start()

frame_cnt = 0
frame_fps = 0
frame_info_show = False

tfps1 = time.perf_counter()
while True:
    try:
        try:
            frame = picam2.capture_array()
        except:
            frame = None
        if frame is None:
            print('image not ready!')
            continue
        cv2.imshow('frame', frame)
        cv2.waitKey(1)
        if frame_info_show:
            frame_info_show = False
            print('FPS = {:5.2f}'.format(frame_fps))
        frame_cnt += 1
        tfps2 = time.perf_counter()
        if (tfps2 - tfps1) > 1.0:
            tfps3 = time.perf_counter()
            frame_fps = frame_cnt / (tfps2-tfps1)
            frame_cnt = 1
            tfps1 = tfps3
            frame_info_show = True

    except Exception as e:
        print(e)

Hardware :
I'm using the latest Picamera2 and raspberry libcamera version on RPi 4B with IMX447 (motorized but not managed yet).

qem@raspberrypi:~ $ uname -a
Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux

qem@raspberrypi:~ $ libcamera-hello --version
libcamera-apps build: 0dc5ea038c79 04-03-2022 (10:35:09)
libcamera build: v0.0.0+3544-22656360

qem@raspberrypi:~ $ pip list | grep picamera2
picamera2         0.2.2

Metering for White Balance

Could Picamera2 operate such that if white balance is supplied, the camera does not meter for it decreasing the over imaging run time? I volunteer at a Planetarium and we use the existing PiCamera to image light pollution. As we want consistency in the images, we set white balance. We have started to experiment with image durations of up to 30 seconds and those run times are quite lengthy.

[BUG] AttributeError: 'Picamera2' object has no attribute 'make_image_'

Please only report one bug per issue!

Describe the bug
capture_image fails at make_image_ on the current build (installed on 2022-06-29).

To Reproduce
capture_image('test.jpg')

Expected behaviour
You should receive the following error.

Exception in thread Thread-41:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/home/rdesc/.local/lib/python3.9/site-packages/picamera2/previews/null_preview.py", line 17, in thread_func
    callback(picam2)
  File "/home/rdesc/.local/lib/python3.9/site-packages/picamera2/previews/null_preview.py", line 40, in handle_request
    completed_request = picam2.process_requests()
  File "/home/rdesc/.local/lib/python3.9/site-packages/picamera2/picamera2.py", line 667, in process_requests
    if function():
  File "/home/rdesc/.local/lib/python3.9/site-packages/picamera2/picamera2.py", line 924, in <lambda>
    self.dispatch_functions([(lambda: self.make_image_(name))], signal_function)
AttributeError: 'Picamera2' object has no attribute 'make_image_'

Hardware :
Raspberry Pi 4B running RPi OS Bullseye 64 bit with PoE+ Hat and RPi HQ Camera.

Additional context
This issue is likely related to the make_image_ call, which has a preceding self. It should probable be a child of the request module. There is no make_image_ function in the Picamera2 class.

Camera cannot be used from a threaded context

from picamera2.picamera2 import *

import threading

picam2 = Picamera2()
preview_config = picam2.preview_configuration()
picam2.configure(preview_config)

def worker():
	print('capturing')
	picam2.capture_file("test.jpg")
	print('captured and saved')

picam2.start()

thread = threading.Thread(target=worker)
thread.start()
print('thread started')
thread.join()
print('thread_completed')

Above is a minimal example of the problem. The problem remains if the camera is passed in as an argument and when it is started from inside the threaded context. From my own testing it seems that it is unable to capture the request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.