User avatar
HermannSW
Posts: 4503
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: libcamera version of raspistill etc. available

Tue Jul 20, 2021 10:41 am

I did complete sync of libcamera-apps and rebuilt, libcamera-base is not found, not sure why. But I can live with the .bashrc workaround, in case it is only my Raspberry Pi OS that shows the issue. On the weekend I had to recover my SD card OS, perhaps something got lost that way:
viewtopic.php?f=29&t=315970

Code: Select all

pi@raspberrypi4B:~/libcamera-apps/build $ ldd ./libcamera-hello  | grep camera
	libcamera.so => /usr/local/lib/arm-linux-gnueabihf/libcamera.so (0xb6802000)
	libcamera-base.so => not found
	libcamera-base.so => not found
pi@raspberrypi4B:~/libcamera-apps/build $ vi ~/.bashrc 
pi@raspberrypi4B:~/libcamera-apps/build $ source ~/.bashrc 
pi@raspberrypi4B:~/libcamera-apps/build $ ldd ./libcamera-hello  | grep camera
	libcamera.so => /usr/local/lib/arm-linux-gnueabihf/libcamera.so (0xb67b8000)
	libcamera-base.so => /usr/local/lib/arm-linux-gnueabihf/libcamera-base.so (0xb6738000)
pi@raspberrypi4B:~/libcamera-apps/build $ 
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4503
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: libcamera version of raspistill etc. available

Tue Jul 20, 2021 5:29 pm

I wanted to test libcamera-jpeg, and used micrometer slide that I got today from visitor here in hospital. I don't know what CS lens I use (will have to look at camera boxes at home). I would never have thought that a camera can "just be" a microscope:
20210720_190535.15%.jpg
20210720_190535.15%.jpg
20210720_190535.15%.jpg (29.46 KiB) Viewed 1088 times

This command captured 12MP photo:

Code: Select all

pi@raspberrypi4B:~ $ libcamera-apps/build/libcamera-jpeg --width 4056 --height 3040 -o t.jpg
Really:

Code: Select all

pi@raspberrypi4B:~ $ file t.jpg 
t.jpg: JPEG image data, Exif standard: [TIFF image data, little-endian, direntries=1], baseline, precision 8, 4056x3040, components 3
pi@raspberrypi4B:~ $ 

12MP photo: https://stamm-wilbrandt.de/en/forum/libcamera/t.jpg
Scaled to 15%:
t.15%.jpg
t.15%.jpg
t.15%.jpg (12.7 KiB) Viewed 1088 times

I measured distance of 20 DIVs as 658 pixels using gimp, that is 3.04µm/pixel(!).
Yes, that is 15x coarser than with 180° lens mounted reversed as macro lens, but still surprising.


Below micrometer slider has DIV=0.01mm, that is 10µm between neighboring divisions:
viewtopic.php?f=43&t=210605&p=1678792&h ... w#p1678792
Image
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

therealdavidp
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 219
Joined: Tue Jan 07, 2020 9:15 am

Re: libcamera version of raspistill etc. available

Fri Jul 23, 2021 11:25 am

Returning to the "libcamera-base.so not found" problem, I've gone through a complete fresh-OS-and-rebuild-from-scratch and everything appears to work fine. I'm wondering a little whether there is some issue updating from older libcamera versions to newer ones that have this new library. Could that be what you did? If so, maybe you could remove the LD_LIBRARY_PATH fix (then check that it's still broken!) and run "sudo ldconfig". Does that fix it?

User avatar
HermannSW
Posts: 4503
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: libcamera version of raspistill etc. available

Fri Jul 23, 2021 5:14 pm

Thanks for the hints.
Yesterday I played with raspiraw, and had to comment out imx477 dtoverlay.
Today I uncommented that overlay, and commented my .bashrc workaround.
After reboot libcamera-hello just works, nothing more needed.
So what you told seems to be correct, since a simple reboot compared to before made libcamera-apps work.

Code: Select all

pi@raspberrypi4B:~/libcamera-apps/build $ echo $LD_LIBRARY_PATH

pi@raspberrypi4B:~/libcamera-apps/build $ 

Code: Select all

pi@raspberrypi4B:~/libcamera-apps/build $ pngtopnm 2021-07-23-191005_800x480_scrot.png | ppmtojpeg > 2021-07-23-191005_800x480_scrot.png.jpg
pi@raspberrypi4B:~/libcamera-apps/build $ 
2021-07-23-191005_800x480_scrot.png.jpg
2021-07-23-191005_800x480_scrot.png.jpg
2021-07-23-191005_800x480_scrot.png.jpg (46.2 KiB) Viewed 1010 times
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

BillyBonce
Posts: 8
Joined: Tue Jul 20, 2021 8:32 am

Re: libcamera version of raspistill etc. available

Tue Jul 27, 2021 12:57 pm

Some question about libcamera...

Code: Select all

uname -a
Linux raspberrypi 5.10.17-v7+ #1421 SMP Thu May 27 13:59:01 BST 2021 armv7l GNU/Linux

Code: Select all

cat /boot/config.txt
# Enable audio (loads snd_bcm2835)
dtparam=audio=on

[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]
dtoverlay=vc4-fkms-v3d
start_x=1
gpu_mem=128
dtoverlay=imx477
disable_touchscreen=1
libcamera and libcamera-app buil as describe in doc

Code: Select all

vcgencmd version
May 27 2021 14:05:31 
Copyright (c) 2012 Broadcom
version 7d9a298cda813f747b51fe17e1e417e7bf5ca94d (clean) (release) (start_x)

vcgencmd get_camera
supported=1 detected=0
Work by ssh with -X.

Command
./libcamera-vid -n -o ~/tst.avi
can`t capture picture till add line
disable_touchscreen=1
to /boot/config.txt

Now I can`t get video till connect display to HDMI connector when Raspberry boot.
./libcamera-vid -n -t 100000 -o ~/tst1.avi

Is this normal operation or have I made some setup mistakes?

therealdavidp
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 219
Joined: Tue Jan 07, 2020 9:15 am

Re: libcamera version of raspistill etc. available

Wed Jul 28, 2021 8:50 am

BillyBonce wrote:
Tue Jul 27, 2021 12:57 pm
Now I can`t get video till connect display to HDMI connector when Raspberry boot.
./libcamera-vid -n -t 100000 -o ~/tst1.avi

Is this normal operation or have I made some setup mistakes?
Hi, thanks for the question. I'm afraid I didn't quite understand what isn't working for you. It sounds like

Code: Select all

./libcamera-vid -n -t 100000 -o ~/tst1.avi
runs without error, is that right? With the -n option I would expect no preview window. Does it write a non-empty output file? One thing to note is that avi is not a supported format, it will write a raw h.264 bitstream. So if instead you use

Code: Select all

./libcamera-vid -n -t 100000 -o ~/tst1.h264
you should find that the file will play successfully with (among others) cvlc. If I have misunderstood, perhaps you could clarify with some example commands and the outputs they produce? Thanks!

dabateman
Posts: 36
Joined: Tue Jul 07, 2020 1:51 pm

Re: libcamera version of raspistill etc. available

Wed Jul 28, 2021 2:56 pm

I just wanted to add that this is working for me on my odd setup.
I have a 4B Pi with 8GB ram.
I have a csi to hdmi adapter to 2m hdmi cable to hdmi to csi adapter to HQ imx477 camera.
I installed the May 2021 64-bit raspberrian beta OS.
Following the instructions fromGithub , I missed the first step of editing the config.txt file. So after full installation I then edited it.
I needed to not only add the dtoverlay for the HQ camera, but correct the vc4 dtoverlay, it was missing the f and had only kms. That check may need to be added even for 4B users. So in editing I added the cma-512 as I primarily use this pi for imaging.
So after rebuilding everything, it all works.
I got Guizero installed and can run my script s. Oddly it can't find PIL, so don't know why. But doesn't impact it.

Now need to sort out the default shutter speed and the gain ranges.

BillyBonce
Posts: 8
Joined: Tue Jul 20, 2021 8:32 am

Re: libcamera version of raspistill etc. available

Wed Jul 28, 2021 6:40 pm

therealdavidp wrote:
Wed Jul 28, 2021 8:50 am
Hi, thanks for the question. I'm afraid I didn't quite understand what isn't working for you. It sounds like
Sorry I will try to explain what I mean...

First - is it normal that the camera does not work until the display is connected at boot?

Second - strange output vcgencmd

Code: Select all

vcgencmd get_camera
supported=1 detected=0
Whom does he support if he hasn't detect anyone?

And on top is a cherry ...
I am trying to write a C ++ application that takes images from a camera and analyzes them
(sorry for the long code, maybe it would be correct to write in the topic in C ++)

Code: Select all

#include <iostream>
#include <memory>

#include <libcamera/libcamera.h>
#include <libcamera/camera_manager.h>
#include <libcamera/camera.h>
#include <libcamera/framebuffer.h>
#include <libcamera/framebuffer_allocator.h>

#include <unistd.h>
#include <fstream>

using namespace std;
using namespace libcamera;

std::string status_to_string(Request::Status status);

FrameBufferAllocator* frameAllocator = nullptr;

void allocatorInit(const shared_ptr<Camera> &camera) {
    frameAllocator = new FrameBufferAllocator(camera);
}

int main() {
    auto manager = make_unique<CameraManager>();
    cout << "version: " << CameraManager::version() << endl;
    manager->start();
    cout << "started" << std::endl;
    const vector<std::shared_ptr<Camera>> &cameras = manager->cameras();
    for(const auto& camera : cameras) {
        cout << "camera: " << camera->id() << endl;
    }

    const auto& camera = cameras[0];
    auto camera_acquire = camera->acquire() == 0;
    cout << "camera_acquire: " << camera_acquire << endl;

    auto config = camera->generateConfiguration({StreamRole::StillCapture});
    config->at(0).pixelFormat = libcamera::formats::BGR888;

    camera->configure(&*config);
    allocatorInit(camera);


    if (camera->start()) throw runtime_error("camera start error");
    cout << "camera started" << endl;

    camera->requestCompleted.connect<void>([](Request* rq) -> void {
        if (rq->status() == Request::RequestCancelled) return;
                ​cout << "requestCompleted" << endl;
       ​const auto& buffer = *rq->buffers().begin();
       ​const auto &plane = *buffer.second->planes().begin();
       ​auto fd = plane.fd.fd();
       ​auto buff = new char[plane.length];
       ​auto received = read(fd, buff, plane.length);
       ​auto f = fopen("data", "w");
       ​fwrite(buff, received, 1, f);
       ​cout << "fwrite" << endl;
       ​fclose(f);
       ​close(fd);
       ​delete[] buff;
       ​cout << "close(fd)" << endl;
   ​});
   ​cout << "camera requestCompleted connect" << endl;

   ​auto rq = camera->createRequest();
   ​auto stream = config->begin()->stream();
   ​frameAllocator->allocate(stream);
   ​const auto& buffers = frameAllocator->buffers(stream);
   ​for(const auto& buffer : buffers) {
       ​rq->addBuffer(stream, &*buffer);
   ​}
   ​camera->queueRequest(&*rq);
   ​while(rq->status() == Request::Status::RequestPending) {
       ​sleep(1);
       ​cout << "wait..." << endl;
   ​}
   ​cout << "request status: " << status_to_string(rq->status()) << endl;

   ​if (camera_acquire) {
       ​cout << "camera stop: " << (camera->stop() == 0) << endl;
       ​cout << "camera release: " << (camera->release() == 0) << endl;
   ​}
   ​manager->stop();
   ​return 0;
}

std::string status_to_string(Request::Status status) {
   ​switch (status) {
       ​case Request::RequestPending: return "RequestPending";
       ​case Request::RequestComplete: return "RequestComplete";
       ​case Request::RequestCancelled: return "RequestCancelled";
   ​}
   ​return "";
}
Say me

Code: Select all

version: v0.0.0+2812-48a380b3
[21:01:16.971764698] [3843]  INFO Camera camera_manager.cpp:294 libcamera v0.0.0+2812-48a380b3
[21:01:16.989204082] [3844]  WARN CameraSensor camera_sensor.cpp:197 'imx477 10-001a': Recommended V4L2 control 0x009a0922 not supported
[21:01:16.989458664] [3844]  WARN CameraSensor camera_sensor.cpp:249 'imx477 10-001a': The sensor kernel driver needs to be fixed
[21:01:16.989606268] [3844]  WARN CameraSensor camera_sensor.cpp:251 'imx477 10-001a': See Documentation/sensor_driver_requirements.rst in the libcamera sources for more information
[21:01:17.001895055] [3844]  WARN CameraSensorProperties camera_sensor_properties.cpp:109 No static properties available for 'imx477'
[21:01:17.002121669] [3844]  WARN CameraSensorProperties camera_sensor_properties.cpp:111 Please consider updating the camera sensor properties database
[21:01:17.002311251] [3844]  WARN CameraSensor camera_sensor.cpp:403 'imx477 10-001a': Failed to retrieve the camera location
[21:01:17.442902043] [3844]  INFO IPAProxy ipa_proxy.cpp:130 libcamera is not installed. Loading IPA configuration from '/home/pi/libcamera/src/ipa/raspberrypi/data'
started
camera: /base/soc/i2c0mux/i2c@1/imx477@1a
camera_acquire: 1
[21:01:17.587765477] [3843]  INFO Camera camera.cpp:906 configuring streams: (0) 4056x3040-BGR888
[21:01:17.588895732] [3844]  INFO RPI raspberrypi.cpp:122 Mode: 1012x760 fmt RG10 Score: 12155.9 (best 12155.9)
[21:01:17.589132189] [3844]  INFO RPI raspberrypi.cpp:122 Mode: 4056x3040 fmt RG12 Score: 500 (best 500)
[21:01:17.589295209] [3844]  INFO RPI raspberrypi.cpp:122 Mode: 2028x1520 fmt RG12 Score: 7596 (best 500)
[21:01:17.589602082] [3844]  INFO RPI raspberrypi.cpp:122 Mode: 2028x1080 fmt RG12 Score: 8679.84 (best 500)
[21:01:17.589790987] [3844]  INFO RPI raspberrypi.cpp:122 Mode: 1012x760 fmt pRAA Score: 11655.9 (best 500)
[21:01:17.589984319] [3844]  INFO RPI raspberrypi.cpp:122 Mode: 4056x3040 fmt pRCC Score: 0 (best 0)
[21:01:17.590132183] [3844]  INFO RPI raspberrypi.cpp:122 Mode: 2028x1520 fmt pRCC Score: 7096 (best 0)
[21:01:17.590283328] [3844]  INFO RPI raspberrypi.cpp:122 Mode: 2028x1080 fmt pRCC Score: 8179.84 (best 0)
[21:01:17.591050095] [3844]  INFO RPI raspberrypi.cpp:620 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected mode: 4056x3040-pRCC
[21:01:17.720481790] [3844]  INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[21:01:17.720650904] [3844]  INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[21:01:17.720750643] [3844]  INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[21:01:17.720862673] [3844]  INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[21:01:17.721114495] [3844]  INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[21:01:17.721245015] [3844]  INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
camera started
camera requestCompleted connect
[21:01:18.232774173] [3843] ERROR Camera camera.cpp:410 Camera in Running state trying exportFrameBuffers() requiring state Configured
[21:01:18.232924380] [3843] ERROR Camera camera.cpp:1000 Request contains no buffers
wait...
wait...
wait...
wait...
wait...
And I ask - maybe I could not configure the camera in the system, but already trying to write code?

therealdavidp
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 219
Joined: Tue Jan 07, 2020 9:15 am

Re: libcamera version of raspistill etc. available

Thu Jul 29, 2021 10:32 am

BillyBonce wrote:
Wed Jul 28, 2021 6:40 pm
First - is it normal that the camera does not work until the display is connected at boot?
The camera should work fine if the display is not connected, it does for me. Can you say more about exactly what operating system you are running? What error messages do you get if you run libcamera-hello?
Second - strange output vcgencmd

Code: Select all

vcgencmd get_camera
supported=1 detected=0
Whom does he support if he hasn't detect anyone?
"vcgencmd get_camera" reports on the proprietary Broadcom camera stack's view of what is connected. With libcamera we drive the camera from the ARM, so the Broadcom stack does not detect it.
And on top is a cherry ...
I am trying to write a C ++ application that takes images from a camera and analyzes them
(sorry for the long code, maybe it would be correct to write in the topic in C ++)

<snip>

And I ask - maybe I could not configure the camera in the system, but already trying to write code?
I think you need to do the allocations before starting the camera. Try moving camera->start() to just before camera->queueRequest(). Hope that helps!

BillyBonce
Posts: 8
Joined: Tue Jul 20, 2021 8:32 am

Re: libcamera version of raspistill etc. available

Fri Jul 30, 2021 10:04 pm

therealdavidp wrote:
Thu Jul 29, 2021 10:32 am
The camera should work fine if the display is not connected, it does for me. Can you say more about exactly what operating system you are running? What error messages do you get if you run libcamera-hello?

Code: Select all

uname -a
Linux raspberrypi 5.10.17-v7+ #1421 SMP Thu May 27 13:59:01 BST 2021 armv7l GNU/Linux
Restart OS without monitor

Code: Select all

ssh -X RspberryPi

pi@raspberrypi:~/libcamera-apps/build $ echo $DISPLAY
localhost:10.0

pi@raspberrypi:~/libcamera-apps/build $ ./libcamera-hello
libEGL warning: DRI3: failed to query the version
libEGL warning: DRI2: failed to authenticate
X Error of failed request:  BadRequest (invalid request code or no such operation)
  Major opcode of failed request:  156 ()
  Minor opcode of failed request:  1
  Serial number of failed request:  15
  Current serial number in output stream:  15
Add environment variable DISPLAY

Code: Select all

DISPLAY=_RaspberryPi_IP_ ./libcamera-still -o ~/still.jpg
[b]Preview window unavailable[/b]
[2:21:14.484741533] [1881]  INFO Camera camera_manager.cpp:294 libcamera v0.0.0+2812-48a380b3
[2:21:14.502926357] [1883]  WARN CameraSensor camera_sensor.cpp:197 'imx477 10-001a': Recommended V4L2 control 0x009a0922 not supported
[2:21:14.503065261] [1883]  WARN CameraSensor camera_sensor.cpp:249 'imx477 10-001a': The sensor kernel driver needs to be fixed
[2:21:14.503121823] [1883]  WARN CameraSensor camera_sensor.cpp:251 'imx477 10-001a': See Documentation/sensor_driver_requirements.rst in the libcamera sources for more information
[2:21:14.510106840] [1883]  WARN CameraSensorProperties camera_sensor_properties.cpp:109 No static properties available for 'imx477'
[2:21:14.510233036] [1883]  WARN CameraSensorProperties camera_sensor_properties.cpp:111 Please consider updating the camera sensor properties database
[2:21:14.510324233] [1883]  WARN CameraSensor camera_sensor.cpp:403 'imx477 10-001a': Failed to retrieve the camera location
[2:21:14.816841481] [1881]  INFO Camera camera.cpp:906 configuring streams: (0) 2028x1520-YUV420
[2:21:14.818129538] [1883]  INFO RPI raspberrypi.cpp:122 Mode: 1012x760 fmt RG10 Score: 5059.89 (best 5059.89)
[2:21:14.818356254] [1883]  INFO RPI raspberrypi.cpp:122 Mode: 4056x3040 fmt RG12 Score: 1387 (best 1387)
[2:21:14.818438180] [1883]  INFO RPI raspberrypi.cpp:122 Mode: 2028x1520 fmt RG12 Score: 500 (best 500)
[2:21:14.818536825] [1883]  INFO RPI raspberrypi.cpp:122 Mode: 2028x1080 fmt RG12 Score: 1583.84 (best 500)
[2:21:14.818643802] [1883]  INFO RPI raspberrypi.cpp:122 Mode: 1012x760 fmt pRAA Score: 4559.89 (best 500)
[2:21:14.818782290] [1883]  INFO RPI raspberrypi.cpp:122 Mode: 4056x3040 fmt pRCC Score: 887 (best 500)
[2:21:14.818886560] [1883]  INFO RPI raspberrypi.cpp:122 Mode: 2028x1520 fmt pRCC Score: 0 (best 0)
[2:21:14.818987392] [1883]  INFO RPI raspberrypi.cpp:122 Mode: 2028x1080 fmt pRCC Score: 1083.84 (best 0)
[2:21:14.819428949] [1883]  INFO RPI raspberrypi.cpp:620 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected mode: 2028x1520-pRCC
[2:21:14.879441946] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: Sharpness = 1.000000
[2:21:14.879721057] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: Saturation = 1.000000
[2:21:14.879809337] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: Contrast = 1.000000
[2:21:14.879908034] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: Brightness = 0.000000
[2:21:14.879985689] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: FrameDurationLimits = [ 33333, 33333 ]
[2:21:14.880202509] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: NoiseReductionMode = 3
[2:21:14.880400007] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: AeMeteringMode = 0
[2:21:14.880619796] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: AeExposureMode = 0
[2:21:14.880705003] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: ExposureValue = 0.000000
[2:21:14.880804950] [1886]  INFO IPARPI raspberrypi.cpp:612 Request ctrl: AwbMode = 0
[2:21:14.884024857] [1883]  INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
No output files created.

Replacing the address with the primary IP and adding the -n switch allows to get an image.
therealdavidp wrote:
Thu Jul 29, 2021 10:32 am
I think you need to do the allocations before starting the camera. Try moving camera->start() to just before camera->queueRequest(). Hope that helps!
Thanks for the advice. Now my application accurately copies the behavior of libcamera-app.
Please tell a newbie why trying to free the cam results in an error

Code: Select all

in code 

manager-> stop ();

raises an error

[0: 08: 30.780954442] [893] ERROR DeviceEnumerator device_enumerator.cpp: 166 Removing media device / dev / media0 while still in use
[0: 08: 30.781187241] [893] ERROR DeviceEnumerator device_enumerator.cpp: 166 Removing media device / dev / media2 while still in use

therealdavidp
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 219
Joined: Tue Jan 07, 2020 9:15 am

Re: libcamera version of raspistill etc. available

Thu Aug 05, 2021 10:59 am

Hi again, sorry for the delay. I've modified your code to avoid the errors:

Code: Select all

#include <iostream>
#include <memory>

#include <libcamera/libcamera.h>
#include <libcamera/camera_manager.h>
#include <libcamera/camera.h>
#include <libcamera/framebuffer.h>
#include <libcamera/framebuffer_allocator.h>

#include <unistd.h>
#include <fstream>

using namespace std;
using namespace libcamera;

std::string status_to_string(Request::Status status);

FrameBufferAllocator* frameAllocator = nullptr;

void allocatorInit(const shared_ptr<Camera> &camera) {
    frameAllocator = new FrameBufferAllocator(camera);
}

int main() {
    auto manager = make_unique<CameraManager>();
    cout << "version: " << CameraManager::version() << endl;
    manager->start();
    cout << "started" << std::endl;
    //const vector<std::shared_ptr<Camera>> &cameras = manager->cameras();
    //for(const auto& camera : cameras) {
	//        cout << "camera: " << camera->id() << endl;
	//    }

    //const auto& camera = cameras[0];
	auto camera = manager->get(manager->cameras()[0]->id());
    auto camera_acquire = camera->acquire() == 0;
    cout << "camera_acquire: " << camera_acquire << endl;

    auto config = camera->generateConfiguration({StreamRole::StillCapture});
    config->at(0).pixelFormat = libcamera::formats::BGR888;

    camera->configure(&*config);
    allocatorInit(camera);


    camera->requestCompleted.connect<void>([](Request* rq) -> void {
											   if (rq->status() == Request::RequestCancelled) return;
											   cout << "requestCompleted" << endl;
											   const auto& buffer = *rq->buffers().begin();
											   const auto &plane = *buffer.second->planes().begin();
											   auto fd = plane.fd.fd();
											   auto buff = new char[plane.length];
											   auto received = read(fd, buff, plane.length);
											   auto f = fopen("data", "w");
											   fwrite(buff, received, 1, f);
											   cout << "fwrite" << endl;
											   fclose(f);
											   //close(fd);
											   //delete[] buff;
											   cout << "close(fd)" << endl;
										   });
	cout << "camera requestCompleted connect" << endl;

	auto rq = camera->createRequest();
	auto stream = config->begin()->stream();
	frameAllocator->allocate(stream);
	const auto& buffers = frameAllocator->buffers(stream);
	for(const auto& buffer : buffers) {
		rq->addBuffer(stream, &*buffer);
	}

    if (camera->start()) throw runtime_error("camera start error");
    cout << "camera started" << endl;

	camera->queueRequest(&*rq);
	while(rq->status() == Request::Status::RequestPending) {
		sleep(1);
		cout << "wait..." << endl;
	}
	cout << "request status: " << status_to_string(rq->status()) << endl;

	if (camera_acquire) {
		cout << "camera stop: " << (camera->stop() == 0) << endl;
		cout << "camera release: " << (camera->release() == 0) << endl;
		camera.reset();
	}
	delete frameAllocator;
	manager->stop();
	return 0;
}

std::string status_to_string(Request::Status status)
{
	switch (status) {
	case Request::RequestPending: return "RequestPending";
	case Request::RequestComplete: return "RequestComplete";
	case Request::RequestCancelled: return "RequestCancelled";
	}
	return "";
}
It seems like you need to take a reference to the camera object otherwise it can get cleared up too early. But for more information on the internals of libcamera, the libcamera-devel mailing list might be a good place for more detailed help (www.libcamera.org).

dgalland
Posts: 65
Joined: Tue Aug 27, 2019 8:20 am

Re: libcamera version of raspistill etc. available

Sun Sep 05, 2021 4:41 pm

I rebuilt libcamera and libcamera-apps without any problem today.
But when I run libcamera-jpeg or libcamera-still it reports the error :
ERROR: *** only single plane YUV supported ***
when encoding jpgeg

therealdavidp
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 219
Joined: Tue Jan 07, 2020 9:15 am

Re: libcamera version of raspistill etc. available

Sun Sep 05, 2021 5:41 pm

Hi, sorry about this, we ran into this at the end of last week too and are on the case. Unfortunately libcamera has shifted underneath our feet so you'll need to check out an older commit until that's sorted out. I believe this libcamera commit is safe: a000a1f6e3208515200aaae6ca8128471c6ed9f3

Return to “Camera board”