Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

can't get image in color mode using opencv c++ with raspberry camera module

i'm using raspberry pi 2 with opencv 3 gold and raspicam-0.1.3 libarrry for the pi camera module I have test the code below and it worked but it provide for me an image in grayscale mode (black and white) but i want it in color mode (RGB)

here is the 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 (! {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.retrieve ( image);
        if ( i%5==0 )  cout<<"\r captured "<<i<<" images"<<std::flush;
    cout<<"Stop camera..."<<endl;
    //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 
    cout<<"Image saved at raspicam_cv_image.jpg"<<endl;

just to notice that i get a colored image when trying the first example here :

what i did is to insert cvtColor(image, cimg, CV_GRAY2RGB); before imwrite but this didn't solve my problem

any help will be appreciated ... thanks