Ask Your Question
0

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

asked 2015-07-09 06:03:09 -0500

franken gravatar image

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 (!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;
}

just to notice that i get a colored image when trying the first example here : http://sourceforge.net/projects/raspi...

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

edit retag flag offensive close merge delete

Comments

In the following line:

Camera.set( CV_CAP_PROP_FORMAT, CV_8UC1 );

CV_8UC1 means a data type of 1 channel of unsigned char.

Try with CV_8UC3 ?

Eduardo gravatar imageEduardo ( 2015-09-11 12:32:56 -0500 )edit

@Eduardo yes you're right , thanks

franken gravatar imagefranken ( 2015-10-12 15:53:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-09-11 12:00:41 -0500

ganday gravatar image

updated 2015-09-12 01:04:12 -0500

berak gravatar image

you set the image to be grayscale mode by setting the format to CV_8UC1. change the format to CV_8UC3!.

**ps this has nothing to with opencv, it is the raspicam thing.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-07-09 06:03:09 -0500

Seen: 1,600 times

Last updated: Sep 12 '15