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 (!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
In the following line:
CV_8UC1 means a data type of 1 channel of unsigned char.
Try with CV_8UC3 ?
@Eduardo yes you're right , thanks