Git Product home page Git Product logo

raspicam's Introduction

RaspiCam: C++ API for using Raspberry camera (with OpenCV)

This library allows to use the Raspberry Pi Camera under BSD License.

The project is started by the AVA research group (rafael Muñoz Salinas; [email protected]) and is now maintained on this GIT repository by Cédric Verstraeten. Please note that is NOT the OFFICIAL repository of RaspiCam, these can be found here.

This repository is used in the Kerberos.io project.

Release notes

Update 2014/03/04: version 0.1.1 released Download at SourceForge Main feaure in 0.0.7 : Still camera API. You can now use the still mode for high resolution (includes OpenCv interface). See examples for more info.

Notes: Requires to update the firmware to use shutterspeed (sudo rpi-update)

Main features

  • Provides class RaspiCam for easy and full control of the camera
  • Provides class RaspiCam_Still and RaspiCam_Still_Cv for controlling the camera in still mode
  • Provides class RaspiCam_Cv for easy control of the camera with OpenCV.
  • Provides class RaspiCam_Still and RaspiCam_Still_Cv for controlling the camera in still mode
  • Provides class RaspiCam_Still and RaspiCam_Still_Cv for using the still camera mode
  • Easy compilation/installation using cmake.
  • No need to install development file of userland. Implementation is hidden.
  • Many examples

Performance Following, we show the capture performance of the library (measured capturing 600 frames). Gray and YUV420 Mode

  • 1280x960: 29.5fps, 640x480 : 29.5fps, 320x240 : 29.5fps RGB Mode
  • 1280x960: 28 fps, 640x480 : 29.29fps, 320x240 : 29.24fps BGR Mode
  • 1280x960: 14 fps, 640x480 : 29.29fps, 320x240 : 29.24fps

Note: when using the full resolution video callbacks with the full resolution of the Raspberry Pi Camera v2, you will likely get an error such as mmal: mmal_vc_port_enable: failed to enable port vc.ril.camera:out:1(BGR3): ENOSPC. In order to fix this increase your GPU memory to at least 256MB.

Color conversion is the most time consuming part. We still need to improve that part. Go to src/private and check if you can contribute!

Note: the library is compiled with the options: -Wall -ffunction-sections -fomit-frame-pointer -O2 -ffast-math -DNDEBUG -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -ftree-vectorize Note 2: the library is currently setting the camera in video mode. So, maximum resolution is 1280x960. I am working on the still port to enable higher resolutions.

Compiling

Clone the repository to your raspberry. Then, uncompress the file and compile

git clone https://github.com/cedricve/raspicam.git
cd raspicam
mkdir build
cd build
cmake ..

At this point you'll see something like

-- CREATE OPENCV MODULE=1
-- CMAKE_INSTALL_PREFIX=/usr/local
-- REQUIRED_LIBRARIES=/opt/vc/lib/libmmal_core.so;/opt/vc/lib/libmmal_util.so;/opt/vc/lib/libmmal.so
-- Change a value with: cmake -D<Variable>=<Value>
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/raspicam/trunk/build

If OpenCV development files are installed in your system, then you see following output; otherwise this option will be 0 and the opencv module of the library will not be compiled.

-- CREATE OPENCV MODULE=1

Finally compile, install and update the ldconfig:

make
sudo make install
sudo ldconfig

After that, you have the programs raspicam_test and raspicam_cv_test (if opencv was enabled) in build/utils. Run the first program to check that compilation is ok.

sudo ./raspicam_test
sudo ./raspicam_cv_test

Using it in your projects

You can learn how to use the library by taking a look at the examples in the utils directory and by analyzing the header files. In addition, we provide a some simple examples on how to use the library with cmake. First, create a directory for our own project. Then, go in and create a file with the name simpletest_raspicam.cpp and add the following code

/**
*/
#include <ctime>
#include <fstream>
#include <iostream>
#include <raspicam/raspicam.h>
using namespace std;
 
int main ( int argc,char **argv ) {
	raspicam::RaspiCam Camera; //Camera object
	//Open camera 
	cout<<"Opening Camera..."<<endl;
	if ( !Camera.open()) {cerr<<"Error opening camera"<<endl;return -1;}
	//wait a while until camera stabilizes
	cout<<"Sleeping for 3 secs"<<endl;
	sleep(3);
	//capture
	Camera.grab();
	//allocate memory
	unsigned char *data=new unsigned char[  Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB )];
	//extract the image in rgb format
	Camera.retrieve ( data,raspicam::RASPICAM_FORMAT_RGB );//get camera image
	//save
	std::ofstream outFile ( "raspicam_image.ppm",std::ios::binary );
	outFile<<"P6\n"<<Camera.getWidth() <<" "<<Camera.getHeight() <<" 255\n";
	outFile.write ( ( char* ) data, Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB ) );
	cout<<"Image saved at raspicam_image.ppm"<<endl;
	//free resrources    
	delete data;
	return 0;
}

For cmake users, create a file named CMakeLists.txt and add:

cmake_minimum_required (VERSION 2.8) 
project (raspicam_test)
find_package(raspicam REQUIRED)
add_executable (simpletest_raspicam simpletest_raspicam.cpp)  
target_link_libraries (simpletest_raspicam ${raspicam_LIBS})

Finally, create build dir,compile and execute

mkdir build
cd build
cmake ..
make
./simpletest_raspicam

If you do not like cmake, simply

g++ simpletest_raspicam.cpp -o simpletest_raspicam -I/usr/local/include -lraspicam -lmmal -lmmal_core -lmmal_util

OpenCV Interface

If the OpenCV is found when compiling the library, the libraspicam_cv.so module is created and the RaspiCam_Cv class available. Take a look at the examples in utils to see how to use the class. In addition, we show here how you can use the RaspiCam_Cv in your own project using cmake.

First create a file with the name simpletest_raspicam_cv.cpp and add the following code

#include <ctime>
#include <iostream>
#include <raspicam/raspicam_cv.h>
using namespace std; 
 
int main ( int argc,char **argv ) {
   
	time_t timer_begin,timer_end;
	raspicam::RaspiCam_Cv Camera;
	cv::Mat image;
	int nCount=100;
	//set camera params
	Camera.set( CV_CAP_PROP_FORMAT, CV_8UC1 );
	//Open camera
	cout<<"Opening Camera..."<<endl;
	if (!Camera.open()) {cerr<<"Error opening the camera"<<endl;return -1;}
	//Start capture
	cout<<"Capturing "<<nCount<<" frames ...."<<endl;
	time ( &timer_begin );
	for ( int i=0; i<nCount; i++ ) {
		Camera.grab();
		Camera.retrieve ( image);
		if ( i%5==0 )  cout<<"\r captured "<<i<<" images"<<std::flush;
	}
	cout<<"Stop camera..."<<endl;
	Camera.release();
	//show time statistics
	time ( &timer_end ); /* get current time; same as: timer = time(NULL)  */
	double secondsElapsed = difftime ( timer_end,timer_begin );
	cout<< secondsElapsed<<" seconds for "<< nCount<<"  frames : FPS = "<<  ( float ) ( ( float ) ( nCount ) /secondsElapsed ) <<endl;
	//save image 
	cv::imwrite("raspicam_cv_image.jpg",image);
	cout<<"Image saved at raspicam_cv_image.jpg"<<endl;
}

For cmake users, create a file named CMakeLists.txt and add:

cmake_minimum_required (VERSION 2.8) 
project (raspicam_test)
find_package(raspicam REQUIRED)
find_package(OpenCV)
IF  ( OpenCV_FOUND AND raspicam_CV_FOUND)
MESSAGE(STATUS "COMPILING OPENCV TESTS")
add_executable (simpletest_raspicam_cv simpletest_raspicam_cv.cpp)  
target_link_libraries (simpletest_raspicam_cv ${raspicam_CV_LIBS})
ELSE()
MESSAGE(FATAL_ERROR "OPENCV NOT FOUND IN YOUR SYSTEM")
ENDIF()

Finally, create,compile and execute

mkdir build
cd build
cmake ..
make
./simpletest_raspicam_cv

If you do not like cmake:

g++ simpletest_raspicam_cv.cpp -o  simpletest_raspicam_cv -I/usr/local/include/ -lraspicam -lraspicam_cv -lmmal -lmmal_core -lmmal_util -lopencv_core -lopencv_highgui 

raspicam's People

Contributors

3t0n avatar arthav24 avatar bryant1410 avatar cedricve avatar davidawad avatar dennisss avatar descampsa avatar detorto avatar fran6co avatar funkmeisterb avatar hodaig avatar ionbazan avatar joshuanapoli avatar mikeymclellan avatar protecto avatar r4ghu avatar ralequi avatar tamamcglinn 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

raspicam's Issues

Underexposed/dark images on raspicam_cv_still

As exposure cannot be set, pictures are often under-exposed.

    case CV_CAP_PROP_EXPOSURE :

// if ( value>0 && value<=100 ) {
// _impl->setShutterSpeed ( Scaler::scale ( 0,100,0,330000, value ) );
// } else {
// _impl->setExposure ( RASPICAM_EXPOSURE_AUTO );
// _impl->setShutterSpeed ( 0 );
// }

Is there a reason why this section is commented out?

Test Program stuck while grab

Hi,

I built raspicam successfully but failed to ran the test program.
The program stuck like the following:

pi@raspberrypi:~/workspace/raspicam/build/utils $ ./raspicam_test
Usage (-help for help)
Connecting to camera
Connected to camera =0000000006384f06 bufs=3686400
Capturing....

I have no idea about what is happening, please help.

Unable to set capture properties after camera is opened

(As mentioned in #15)

When using the RaspiCam_CV class, properties cannot be set after camera is opened. This forces me to release and re-open the camera to set properties, which I'm hoping could be avoided.

How can I set properties after camera is opened? Is it enough to invoke mmal_port_parameter_set_boolean(camera_video_port, MMAL_PARAMETER_CAPTURE, 0)?

Using PiCamera v2 with full 3280x2460 resolution

Hi,
i am using this raspicam.h in the https://gitlab.inria.fr/line/aide-group/aide project, really fine, and experiment bith raspicam::RaspiCam and raspicam::RaspiCam_cv with a PiCamera v2 which hardware characterisrics are e.g. there https://picamera.readthedocs.io/en/release-1.12/fov.html

But i only can use a 1280x960 while 3280x2460 resolution is possible, but it fails (see bug log below) it might be some buffer size is not large enough ?

Please.
Best.

P.S.: i gonna have side question : what is RaspiCam_Still ? it might be link with my question.


Thread 3 "vc.ril.camera" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x6e5feed0 (LWP 7471)]
0x76fba444 in memcpy () from /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so
--- backtrace ------------------------------------------------------------------------------#0 0x76fba444 in memcpy ()
at /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so
#1 0x00000000 in ()
--- backtrace full -------------------------------------------------------------------------#0 0x76fba444 in memcpy ()
at /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so
#1 0x00000000 in ()

the image is bluish

Camera.set( CV_CAP_PROP_FORMAT, CV_8UC3 );
//Camera.set( CV_CAP_PROP_WHITE_BALANCE_RED_V, -1 ); // auto whitebalance
//Camera.set( CV_CAP_PROP_WHITE_BALANCE_BLUE_U, -1 );

how to make it show better

raspicam_test works but raspicam_still_test get locked. Any idea

Bonjour,
As explained in the title I'm able to compile and build the lib as well as raspicam_test and raspicam_still_test (open CV is not installed)

1 - raspicam_test works like a charm. It reports 14 FPS. I don't know if it is OK (I use a Raspberry Pi 3). Could you please confirm if 14FPS is OK or not.
2 - raspicam_still_test get stopped right after it output "Initializing".
I'm just starting with raspicam and I have no idea of what may happen. I looked into the code. But since I don't yet have an IDE set up (with debugger etc) I'm not really able to "see" what is causing the issue. So far I can only comment one line at a time and see what happen... It will be a long night if I follow that path... So any advise/help will be appreciated.

Best regards, Philippe

PS : By the way, what is the purpose of the raspicam_still_test and what is exactly the "still mode" (if one exist). Sorry, this may be a silly question but again, I just plugged my camera tonight.

Text overlay...

Hi,
is there a way to put some "dynamic" text over video and save the stream to file?

errors when making from raspicam_cv.cpp

when I was making, I met the following errors:

/home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp: In constructor ‘raspicam::RaspiCam_Cv::RaspiCam_Cv()’: /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:46:6: error: ‘CAP_PROP_FORMAT’ is not a member of ‘cv’ set(cv::CAP_PROP_FORMAT,CV_8UC3); ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp: In member function ‘double raspicam::RaspiCam_Cv::get(int)’: /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:95:14: error: ‘CAP_PROP_MODE’ is not a member of ‘cv’ case cv::CAP_PROP_MODE: ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:97:14: error: ‘CAP_PROP_FRAME_WIDTH’ is not a member of ‘cv’ case cv::CAP_PROP_FRAME_WIDTH : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:99:14: error: ‘CAP_PROP_FRAME_HEIGHT’ is not a member of ‘cv’ case cv::CAP_PROP_FRAME_HEIGHT : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:101:14: error: ‘CAP_PROP_FPS’ is not a member of ‘cv’ case cv::CAP_PROP_FPS: ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:103:14: error: ‘CAP_PROP_FORMAT’ is not a member of ‘cv’ case cv::CAP_PROP_FORMAT : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:105:14: error: ‘CAP_PROP_BRIGHTNESS’ is not a member of ‘cv’ case cv::CAP_PROP_BRIGHTNESS : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:107:14: error: ‘CAP_PROP_CONTRAST’ is not a member of ‘cv’ case cv::CAP_PROP_CONTRAST : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:109:14: error: ‘CAP_PROP_SATURATION’ is not a member of ‘cv’ case cv::CAP_PROP_SATURATION : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:112:14: error: ‘CAP_PROP_GAIN’ is not a member of ‘cv’ case cv::CAP_PROP_GAIN : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:114:14: error: ‘CAP_PROP_EXPOSURE’ is not a member of ‘cv’ case cv::CAP_PROP_EXPOSURE : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp: In member function ‘bool raspicam::RaspiCam_Cv::set(int, double)’: /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:130:14: error: ‘CAP_PROP_MODE’ is not a member of ‘cv’ case cv::CAP_PROP_MODE: ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:134:14: error: ‘CAP_PROP_FRAME_WIDTH’ is not a member of ‘cv’ case cv::CAP_PROP_FRAME_WIDTH : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:137:14: error: ‘CAP_PROP_FRAME_HEIGHT’ is not a member of ‘cv’ case cv::CAP_PROP_FRAME_HEIGHT : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:140:14: error: ‘CAP_PROP_FORMAT’ is not a member of ‘cv’ case cv::CAP_PROP_FORMAT :{ ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:153:14: error: ‘CAP_PROP_BRIGHTNESS’ is not a member of ‘cv’ case cv::CAP_PROP_BRIGHTNESS : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:156:14: error: ‘CAP_PROP_CONTRAST’ is not a member of ‘cv’ case cv::CAP_PROP_CONTRAST : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:159:14: error: ‘CAP_PROP_SATURATION’ is not a member of ‘cv’ case cv::CAP_PROP_SATURATION : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:163:14: error: ‘CAP_PROP_GAIN’ is not a member of ‘cv’ case cv::CAP_PROP_GAIN : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:166:14: error: ‘CAP_PROP_EXPOSURE’ is not a member of ‘cv’ case cv::CAP_PROP_EXPOSURE : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:174:14: error: ‘CAP_PROP_CONVERT_RGB’ is not a member of ‘cv’ case cv::CAP_PROP_CONVERT_RGB : ^~ /home/pi/Downloads/raspicam-master/src/raspicam_cv.cpp:177:14: error: ‘CAP_PROP_FPS’ is not a member of ‘cv’ case cv::CAP_PROP_FPS: ^~ src/CMakeFiles/raspicam_cv.dir/build.make:62: recipe for target 'src/CMakeFiles/raspicam_cv.dir/raspicam_cv.cpp.o' failed
do you have some ideas about the errors

Raspicam vs OpenCV VideoCapture

Can you please write a few sentences in the readme about what's the difference between OpenCV VideoCapture to the RaspiCam? Why/when should we use it?

Missed Private_Impl::getVideoStabilization

In Private_Impl class defined function setVideoStabilization, and this function param setted to State.videoStabilisation.
But, in Private_Impl not defined getVideoStabilization.

If necessary, i can create a merge request with the necessary changes.

Sorry for my bad english.

Maximum fps is 33.33 for 640x480 image

With the following set up, although raspicam is capable of working at 90fps, I am unable to get 90 fps when I use grab, in a for loop. Is there a way around this?

Camera.set (CV_CAP_PROP_FRAME_WIDTH, 640);
Camera.set (CV_CAP_PROP_FRAME_HEIGHT, 480);
Camera.set (CV_CAP_PROP_FPS, 90);

Raspberry Pi4 CM

sudo ./raspicam_test
Error:
mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
Solution:
sudo raspi-config
Interface Options -> Legacy camera enable -> yes

How many frames are buffered?

Hi
Thanks for the library

How many frames are buffered when the grab() is not called for a long time? OpenCV's VideoCapture buffers 5 frames. How about Raspicam?

Cmake error

Hello,
I installed api to my raspberry pi and pre-build examples work fine. But when I try to build my own project (as suggested in tutorial) cmake gives an error (CMake Error at CMakeLists.txt:3 (find package) and I can't build a project :/ The location of project /raspicam and location of api /Downloads/raspicam-0.1.3
Could you help me please with this issue!?

issue with ENOSPC(but not the same one with in introduce)

the issure is:
/home/pi/raspicam/src/private/private_impl.cpp:187 :Private_Impl::retrieve type is not RASPICAM_FORMAT_IGNORE as it should be
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates

i have increase my GPÜ to 512MB,but it's useless,i hpe someone can help me with this issure,thank you!

Use of raspicam in stereo mode

Hi,

I would like no know if it is possible to use raspicam API with the StereoPI computer (a raspberry pi with two camera ports -- see details in https://stereopi.com/). What i need is to grab sincronyzed frames from both cameras at once.

Thank you!

Can't compile the library

I'm trying to compile the library on a Pi 4 64-bit Raspberry OS.
I get the following error

[  4%] Linking CXX shared library libraspicam_cv.so
/usr/bin/ld: /opt/vc/lib/libmmal_core.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/raspicam_cv.dir/build.make:248: src/libraspicam_cv.so] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:170: src/CMakeFiles/raspicam_cv.dir/all] Fehler 2
make: *** [Makefile:149: all] Fehler 2

aarch64 build

Hi,
has anyone tried to build this for aarch64? I know V4 is a 32bit GPU, but the interface dependencies are shipped with this library so I thought this could work right?? Userland is not 64bit right now but could be compiled 64bit I guess...

Greetings

Please add a LICENSE file

While the README.md states the "BSD License", it's a bit unclear whether it's 2-Clause or 3-Clause BSD. Also, GitHub does not display the license as part of the repository header unless a LICENSE file is added. This can be easily done via the web-interface, which has the advance of getting the license text from a drop-down.

Unable to run simpletest_raspicam.cpp

Hello everyone:
I have successfully installed the library on the Raspberry Pi, but when I try to run simpletest_raspicam.cpp, there is an error.
/usr/bin/ld: cannot find -lmmal
/usr/bin/ld: cannot find -lmmal_core
/usr/bin/ld: cannot find -lmmal_util
I tried to download other versions and still can't solve it.
I hope to hear from you for your help and advice.

Images change in color

I have set the resolution at 640x480, exposure at 100, fps at 30 and white balances at 100. But the captured images are different in color! Some of them are bluish. I tried using OpenCV's cvtColor to change from RGB to BGR but the bluish images became reddish!
How should I solve the issue?

Multiple cameras

How can we address which camera to use?
I have two on my system.

pixel value not saturated at 255

Hi I am using the official raspicam, however I found that the maximum pixel value is always less than 255, even when the image looks totally saturated. Just want to know if you had the same problem? thanks

Raspicam_cv and Raspicam

Due to normalization, the images are underexposed and too dark, as shutter speed is limited to 33ms
case CV_CAP_PROP_EXPOSURE :
if ( _impl->getShutterSpeed() ==0 )
return -1;//auto
else return Scaler::scale (0,330000, 0,100, _impl->getShutterSpeed() ) ;
break;

Corruption when frame size changes

I'm trying to use raspicam_cv to get frames from the camera continuously. I can get the frames properly without making any changes. But if I change the frame sizes, the frames that come in are corrupted.
First if i add these settings to camera frames that come in corrupted;

cap->set(CV_CAP_PROP_FRAME_WIDTH , 176);
cap->set(CV_CAP_PROP_FRAME_HEIGHT, 144);

raspicam_cv_image1

This frame is the size I want, but it's still broken.

Raspicam + OpenCV = stripes and duplicates

Hello,

I was trying the OpenCV example on an raspberry Pi 3. The simple_test or raspistill gives me a clear image. If I use the OpenCV example and imshow(frame), I receive stripes and duplicates. See picture. Does anyone know why? I tried two brand new cameras and PIs + PSU.
Thanks!

raspicam_opencv

Retrieve Speed

I have the Raspberry Pi Cam 2 NoIR on a Raspberry Pi Zero, and I am successfully capturing frames with the following code, which is based heavily on the sample code provided in this repo.

I changed it to color format (CV_8UC3) and set the width and height to the maximum supported by video mode --- which is supposed to support 15 frames per second.

I would prefer to use the still capture mode, but I am ok using the video capture. I would like as high a resolution as possible.

The Camera.retrieve(image); step takes close to 3-4 seconds to execute, I would expect it to take under 100ms to support 15 fps.

Is there something obvious I am missing? Is it possible to have the camera waiting for still capture and trigger it quickly? Or is it better to have the video running in a continual loop like I have and simply take the next frame when I need it?

void CServer::roll() {

    raspicam::RaspiCam_Cv Camera;

    Camera.set( CV_CAP_PROP_FORMAT, CV_8UC3 );
    Camera.set( CV_CAP_PROP_FRAME_WIDTH, 2592 );
    Camera.set( CV_CAP_PROP_FRAME_HEIGHT, 1944 );
    Camera.set( CV_CAP_PROP_FPS, 15 );
    

    //Open camera
    cout<<"Opening Camera..."<<endl;
    if (!Camera.open()) {cerr<<"Error opening the camera"<<endl;return;}

    //wait a while until camera stabilizes
    sleep(3);
    cout<<"Camera ready..."<<endl;

    cv::Mat image;

    vector<int> compression_params;
    compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
    compression_params.push_back(9);

    while(true) {
            cout<<"Camera Grab..."<<endl;
            Camera.grab();

            cout<<"Camera Retrieve to Mat..."<<endl;
            Camera.retrieve(image);
            
            cout<<"Image saved at image.png"<<endl;
            cv::imwrite("image.png", image, compression_params);
            
    }
}

Shutter lag for still photography (also frame synchronization)

Hello,

this is not a bug but rather a question - what is the shutter lag using the Camera.grab() or Camera.grab_retrieve() functions?

There are some discussions online on the topic of frame synchronization or shutter lag/delay - it seems like the sensor is in free running mode for video (which one would expect there) but I was not able to confirm for still photography (but I suspect the same). This would mean that the trigger actually can not be controlled and only the "last" image from the free run is grabbed and returned. As you worked with the MMAL can you confirm how the captures (for stills) work on low level?

This posts mentions a delay in the "order of 1ms" but I am not sure it really talks about the lag. When I look a the raspistill.c code it features few interesting modes like FRAME_NEXT_KEYPRESS or FRAME_NEXT_SIGNAL which should be a kind of trigger but I do not have the resources to dive into the code deep enough to figure out about the shutter lag.

Some links:
http://raspberrypi.stackexchange.com/questions/28113/raspberry-pi-camera-when-is-it-ready-for-next-frame
http://raspberrypi.stackexchange.com/questions/51603/syncing-image-capture-on-raspberry-pi-3-using-picamera-v2

Any info from your side will be very helpful to me! Thanks in advance!

Issue with make

I have to run the project on Raspberry Pi. So, I think I used the same repository on a different Pi and it was working fine, but now I'm having this issue of undefined reference on a different Pi. I am not sure if it's the raspicam or something else. Hoping someone can help me fix this issue. Thanks.

[ 72%] Linking CXX executable raspicam_test ../src/libraspicam.so.0.1.2: undefined reference to mmal_util_rgb_order_fixed'
collect2: error: ld returned 1 exit status
utils/CMakeFiles/raspicam_test.dir/build.make:98: recipe for target 'utils/raspicam_test' failed
make[2]: *** [utils/raspicam_test] Error 1
CMakeFiles/Makefile2:217: recipe for target 'utils/CMakeFiles/raspicam_test.dir/all' failed
make[1]: *** [utils/CMakeFiles/raspicam_test.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

I used the one found on sourceforge too. That one compiles without any issue, but I am not able to compile my program as it says :
/usr/local/lib/libraspicam_cv.so: undefined reference to raspicam::_private::Private_Impl::setContrast(int)' /usr/local/lib/libraspicam_cv.so: undefined reference to raspicam::_private::Private_Impl::setBrightness(unsigned int)'
/usr/local/lib/libraspicam_cv.so: undefined reference to raspicam::_private::Private_Impl::setExposure(raspicam::RASPICAM_EXPOSURE)' /usr/local/lib/libraspicam_cv.so: undefined reference to raspicam::_private::Private_Impl::setSaturation(int)'
/usr/local/lib/libraspicam_cv.so: undefined reference to raspicam::_private::Private_Impl_Still::setISO(int)' /usr/local/lib/libraspicam_cv.so: undefined reference to raspicam::_private::Private_Impl_Still::setEncoding(raspicam::RASPICAM_ENCODING)'
/usr/local/lib/libraspicam_cv.so: undefined reference to `raspicam::_private::Private_Impl_Still::initialize()'

Installation on Manjaro (RPi3B)

I can't install raspicam on my RPi3B with Manjaro installation. Also I don't want to switch to Raspbian because I'm already set only without camera set.

 ✘ unity@earth  /tmp/raspicam/build   master  uname -a
Linux earth 5.10.25-3-MANJARO-ARM #1 SMP PREEMPT Sat Mar 27 11:17:24 CDT 2021 aarch64 GNU/Linux

Here is the logs:

 unity@earth  ~cd /tmp
 unity@earth  /tmp  git clone https://github.com/cedricve/raspicam.git
cd raspicam
mkdir build
cd build
cmake ..

Cloning into 'raspicam'...
remote: Enumerating objects: 723, done.
remote: Total 723 (delta 0), reused 0 (delta 0), pack-reused 723
Receiving objects: 100% (723/723), 803.34 KiB | 2.40 MiB/s, done.
Resolving deltas: 100% (383/383), done.
CMake Deprecation Warning at CMakeLists.txt:4 (CMAKE_MINIMUM_REQUIRED):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:49 (MESSAGE):
  Could not find mmal libraries


-- Configuring incomplete, errors occurred!
See also "/tmp/raspicam/build/CMakeFiles/CMakeOutput.log".
 ✘ unity@earth  /tmp/raspicam/build   master  

File: /tmp/raspicam/build/CMakeFiles/CMakeOutput.log

Unable to build with open cv installed

dainius@dainius-VirtualBox:/ProjectFiles/Utilities/raspicam/build$ cmake .. && make
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- -------------------------------------------------------------------------------
-- GNU COMPILER
-- -------------------------------------------------------------------------------
-- Adding cv library
-- 
-- -------------------------------------------------------------------------------
-- General configuration for raspicam 0.1.2
-- -------------------------------------------------------------------------------
-- 
    Built as dynamic libs?:ON
    Compiler:/usr/bin/c++
-- C++ flags (Release):        -Wno-pedantic -Wall -Wno-variadic-macros -std=c++0x -Wl,--no-as-needed  -Wall -Wno-long-long -ffunction-sections   -fomit-frame-pointer -O3 -ffast-math -mmmx -msse -msse2 -msse3 -DNDEBUG  -lpthread
-- C++ flags (Debug):          -Wno-pedantic -Wall -Wno-variadic-macros -std=c++0x -Wl,--no-as-needed  -Wall -Wno-long-long -ffunction-sections  -g3 -O0 -DDEBUG -D_DEBUG -W -Wextra -Wno-return-type  -lpthread
-- CMAKE_CXX_FLAGS:          -Wno-pedantic -Wall -Wno-variadic-macros -std=c++0x -Wl,--no-as-needed  -Wall -Wno-long-long -ffunction-sections 
-- CMAKE_BINARY_DIR:         /ProjectFiles/Utilities/raspicam/build
-- 
-- CMAKE_SYSTEM_PROCESSOR = x86_64
-- BUILD_SHARED_LIBS = ON
-- BUILD_UTILS = ON
-- CMAKE_INSTALL_PREFIX = /usr/local
-- CMAKE_BUILD_TYPE = Release
-- CMAKE_MODULE_PATH = /usr/local/lib/cmake/;/usr/lib/cmake
-- 
-- CREATE OPENCV MODULE=1
-- CMAKE_INSTALL_PREFIX=/usr/local
-- REQUIRED_LIBRARIES=
-- 
-- 
-- Change a value with: cmake -D<Variable>=<Value>
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /ProjectFiles/Utilities/raspicam/build
Scanning dependencies of target raspicam
[  4%] Building CXX object src/CMakeFiles/raspicam.dir/raspicam.cpp.o
[  8%] Building CXX object src/CMakeFiles/raspicam.dir/raspicam_still.cpp.o
[ 12%] Building CXX object src/CMakeFiles/raspicam.dir/private/private_impl.cpp.o
[ 16%] Building CXX object src/CMakeFiles/raspicam.dir/private/threadcondition.cpp.o
[ 20%] Building CXX object src/CMakeFiles/raspicam.dir/private_still/private_still_impl.cpp.o
[ 25%] Building CXX object src/CMakeFiles/raspicam.dir/private/fake_mmal_dependencies.cpp.o
[ 29%] Linking CXX shared library libraspicam.so
[ 29%] Built target raspicam
Scanning dependencies of target raspicam_cv
[ 33%] Building CXX object src/CMakeFiles/raspicam_cv.dir/raspicam_cv.cpp.o
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp: In constructor ‘raspicam::RaspiCam_Cv::RaspiCam_Cv()’:
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:46:6: error: ‘CAP_PROP_FORMAT’ is not a member of ‘cv’
  set(cv::CAP_PROP_FORMAT,CV_8UC3);
      ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp: In member function ‘double raspicam::RaspiCam_Cv::get(int)’:
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:95:14: error: ‘CAP_PROP_MODE’ is not a member of ‘cv’
         case cv::CAP_PROP_MODE:
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:97:14: error: ‘CAP_PROP_FRAME_WIDTH’ is not a member of ‘cv’
         case cv::CAP_PROP_FRAME_WIDTH :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:99:14: error: ‘CAP_PROP_FRAME_HEIGHT’ is not a member of ‘cv’
         case cv::CAP_PROP_FRAME_HEIGHT :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:101:14: error: ‘CAP_PROP_FPS’ is not a member of ‘cv’
         case cv::CAP_PROP_FPS:
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:103:14: error: ‘CAP_PROP_FORMAT’ is not a member of ‘cv’
         case cv::CAP_PROP_FORMAT :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:105:14: error: ‘CAP_PROP_BRIGHTNESS’ is not a member of ‘cv’
         case cv::CAP_PROP_BRIGHTNESS :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:107:14: error: ‘CAP_PROP_CONTRAST’ is not a member of ‘cv’
         case cv::CAP_PROP_CONTRAST :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:109:14: error: ‘CAP_PROP_SATURATION’ is not a member of ‘cv’
         case cv::CAP_PROP_SATURATION :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:112:14: error: ‘CAP_PROP_GAIN’ is not a member of ‘cv’
         case cv::CAP_PROP_GAIN :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:114:14: error: ‘CAP_PROP_EXPOSURE’ is not a member of ‘cv’
         case cv::CAP_PROP_EXPOSURE :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp: In member function ‘bool raspicam::RaspiCam_Cv::set(int, double)’:
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:130:14: error: ‘CAP_PROP_MODE’ is not a member of ‘cv’
         case cv::CAP_PROP_MODE:
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:134:14: error: ‘CAP_PROP_FRAME_WIDTH’ is not a member of ‘cv’
         case cv::CAP_PROP_FRAME_WIDTH :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:137:14: error: ‘CAP_PROP_FRAME_HEIGHT’ is not a member of ‘cv’
         case cv::CAP_PROP_FRAME_HEIGHT :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:140:14: error: ‘CAP_PROP_FORMAT’ is not a member of ‘cv’
         case cv::CAP_PROP_FORMAT :{
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:153:14: error: ‘CAP_PROP_BRIGHTNESS’ is not a member of ‘cv’
         case cv::CAP_PROP_BRIGHTNESS :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:156:14: error: ‘CAP_PROP_CONTRAST’ is not a member of ‘cv’
         case cv::CAP_PROP_CONTRAST : 
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:159:14: error: ‘CAP_PROP_SATURATION’ is not a member of ‘cv’
         case cv::CAP_PROP_SATURATION :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:163:14: error: ‘CAP_PROP_GAIN’ is not a member of ‘cv’
         case cv::CAP_PROP_GAIN :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:166:14: error: ‘CAP_PROP_EXPOSURE’ is not a member of ‘cv’
         case cv::CAP_PROP_EXPOSURE :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:174:14: error: ‘CAP_PROP_CONVERT_RGB’ is not a member of ‘cv’
         case cv::CAP_PROP_CONVERT_RGB :
              ^
/ProjectFiles/Utilities/raspicam/src/raspicam_cv.cpp:177:14: error: ‘CAP_PROP_FPS’ is not a member of ‘cv’
         case cv::CAP_PROP_FPS:
              ^
src/CMakeFiles/raspicam_cv.dir/build.make:62: recipe for target 'src/CMakeFiles/raspicam_cv.dir/raspicam_cv.cpp.o' failed
make[2]: *** [src/CMakeFiles/raspicam_cv.dir/raspicam_cv.cpp.o] Error 1
CMakeFiles/Makefile2:156: recipe for target 'src/CMakeFiles/raspicam_cv.dir/all' failed
make[1]: *** [src/CMakeFiles/raspicam_cv.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Why can't shutterspeed be set?

This is a great library, but I need to be able to capture at high frame rates (> 120fps), and currently the shutterspeed can't be set.
I've captured video at such framerates with the default raspivid (from raspbian), so why can't the shutterseep in raspicam be set?
What has to be done to be able to use this property?

Reference:
Shutterspeed is currently set to automatic. The setter is never used, nor can be used. This implicates that the getter will always return -1

Originally posted by @cedricve in #2 (comment)

The CPU is fully loaded!

Hi

I'm using raspicam with ROS to stream some captured images with Raspberry Pi Zero. Running htop shows that the CPU is 100% working! Is there functions in raspicam that use the CPU?

RAW image support

Hello,

Can your project acquire RAW still images from the raspberry pi camera?
(I haven't seen mention in the code, sorry if asking this question here is inappropriate)

Thanks, wall0159

Unable to re-capture image with new parameters

My code is something like this:

{ 
   //...
   {
     Raspicam camera;
     camera.setwidth(320);
     camera.setheight(240)
     camera.open()
     //.. get buffer size and allocate memmory
     camera.grab_retreive(buffer,length)
   }

   {
     Raspicam camera;
     camera.setwidth(320);
     camera.setheight(240)
     camera.open()
     //.. get buffer size and allocate memmory
     camera.grab_retreive(buffer,length)
   }
}

The error on the second open is:
mmal_vc_component_enable: falied to enable component : ENOSPC

Is this a limitation of the camera and its drivers or with Raspicam?

Reducing frame width and height yields strange images

Hi,

I want to to reduce the image quality before capturing. I reduce the frame width and height like I normally would in OpenCV but with raspicam I get some strange results. This is my test code:

#include <raspicam/raspicam_cv.h>

int main ( int argc,char **argv ) {

    raspicam::RaspiCam_Cv Camera;
	Camera.set( CV_CAP_PROP_FORMAT, CV_8UC1 );
	
    cv::Mat image;

    if (!Camera.open()) {return -1;}

    Camera.set(CV_CAP_PROP_FRAME_WIDTH, 640); // <-- If i remove this and the next line, the images are "normal"
    Camera.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

    Camera.grab();
    Camera.retrieve(image);

    Camera.release();

    //save image 
    cv::imwrite("raspicam_cv_image.jpg",image);
    return 0;
}

Resulting image: http://i.imgur.com/u07TCX0.jpg

If I don't reduce the frame size (i.e. comment out the lines setting the properties), the image is normal.

Hardware:

RaspiCam_Still Locks up after capturing

Hi,

I am having trouble to get the raspicam_still_test working. compiling and linking went without any problems. running raspicam_test works just fine but when I want to run raspicam_still_test it locks up and stops seeming to wait for something. I need the raspicam_still_test because I want to take some detailed pictures.

pi@rootcampi1:~/Downloads/raspicam/build/utils $ sudo raspicam_still_test 
-w val : sets image width (2592 default)
-h val : sets image height (1944 default)
-iso val: set iso [100,800] (400 default)
Initializing ...2592x1944
capture

Edit:
added some comments in the code

  bool Private_Impl_Still::takePicture ( unsigned char * preallocated_data, unsigned int length ) {
        initialize();
		cout << "1"<<endl;
        int ret = 0;
        sem_t mutex;
        sem_init ( &mutex, 0, 0 );
		cout << "2"<<endl;
        RASPICAM_USERDATA * userdata = new RASPICAM_USERDATA();
        userdata->cameraBoard = this;
        userdata->encoderPool = encoder_pool;
        userdata->mutex = &mutex;
        userdata->data = preallocated_data;
        userdata->bufferPosition = 0;
        userdata->offset = 0;
        userdata->startingOffset = 0;
        userdata->length = length;
        userdata->imageCallback = NULL;
		cout << "3"<<endl;
        encoder_output_port->userdata = ( struct MMAL_PORT_USERDATA_T * ) userdata;
        if ( ( ret = startCapture() ) != 0 ) {
            delete userdata;
            return false;
        }
		cout << "4"<<endl;;
        sem_wait ( &mutex );
		cout << "5"<<endl;
        sem_destroy ( &mutex );
		cout << "6"<<endl;;
        stopCapture();
		cout << "7"<<endl;
        delete userdata;

        return true;
    }

    int Private_Impl_Still::startCapture() {
        // If the parameters were changed and this function wasn't called, it will be called here
        // However if the parameters weren't changed, the function won't do anything - it will return right away
        commitParameters();
		cout << "3-1\n";
        
		if ( encoder_output_port->is_enabled ) {
            cout << API_NAME << ": Could not enable encoder output port. Try waiting longer before attempting to take another picture.\n";
            return -1;
        }
		cout << "3-2\n";
        if ( mmal_port_enable ( encoder_output_port, buffer_callback ) != MMAL_SUCCESS ) {
            cout << API_NAME << ": Could not enable encoder output port.\n";
            return -1;
        }
		cout << "3-4\n";
        int num = mmal_queue_length ( encoder_pool->queue );
        for ( int b = 0; b < num; b++ ) {
            MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get ( encoder_pool->queue );

            if ( !buffer )
                cout << API_NAME << ": Could not get buffer (#" << b << ") from pool queue.\n";

            if ( mmal_port_send_buffer ( encoder_output_port, buffer ) != MMAL_SUCCESS )
                cout << API_NAME << ": Could not send a buffer (#" << b << ") to encoder output port.\n";
        }
        if ( mmal_port_parameter_set_boolean ( camera_still_port, MMAL_PARAMETER_CAPTURE, 1 ) != MMAL_SUCCESS ) {
            cout << API_NAME << ": Failed to start capture.\n";
            return -1;
        }
		
		cout << "3-5\n";
        return 0;
    }

output:

pi@rootcampi1:~/Downloads/raspicam/build/utils $ ./raspicam_still_test
-w val : sets image width (2592 default)
-h val : sets image height (1944 default)
-iso val: set iso [100,800] (400 default)
Initializing ...2592x1944
capture
00
0
1
2
3
3-1
3-2
3-4
3-5
4

it seems to be waiting at:

sem_wait ( &mutex );

any idea why start capture would not release the mutex?

Edit2:

so it never gets released because buffer_callback never gets called. I have no clue how mmal works so I cant really look into why its not running

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.