error about cvtColor
Hello, I am using the opencv to compare images with the code compareHist_Demo.cpp, here is my code
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include "raspicam_cv.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <wiringSerial.h>
#include <wiringPi.h>
using namespace cv;
using namespace std;
bool doTestSpeedOnly=false;
//parse command line
//returns the index of a command line param in argv. If not found, return -1
int findParam ( string param,int argc,char **argv ) {
int idx=-1;
for ( int i=0; i<argc && idx==-1; i++ )
if ( string ( argv[i] ) ==param ) idx=i;
return idx;
}
//parse command line
//returns the value of a command line param. If not found, defvalue is returned
float getParamVal ( string param,int argc,char **argv,float defvalue=-1 ) {
int idx=-1;
for ( int i=0; i<argc && idx==-1; i++ )
if ( string ( argv[i] ) ==param ) idx=i;
if ( idx==-1 ) return defvalue;
else return atof ( argv[ idx+1] );
}
void processCommandLine ( int argc,char **argv,raspicam::RaspiCam_Cv &Camera ) {
Camera.set ( CV_CAP_PROP_FRAME_WIDTH, getParamVal ( "-w",argc,argv,192 ) );
Camera.set ( CV_CAP_PROP_FRAME_HEIGHT, getParamVal ( "-h",argc,argv,144 ) );
Camera.set ( CV_CAP_PROP_BRIGHTNESS,getParamVal ( "-br",argc,argv,50 ) );
Camera.set ( CV_CAP_PROP_CONTRAST ,getParamVal ( "-co",argc,argv,50 ) );
Camera.set ( CV_CAP_PROP_SATURATION, getParamVal ( "-sa",argc,argv,50 ) );
Camera.set ( CV_CAP_PROP_GAIN, getParamVal ( "-g",argc,argv ,50 ) );
if ( findParam ( "-gr",argc,argv ) !=-1 )
Camera.set ( CV_CAP_PROP_FORMAT, CV_8UC1 );
if ( findParam ( "-test_speed",argc,argv ) !=-1 )
doTestSpeedOnly=true;
if ( findParam ( "-ss",argc,argv ) !=-1 )
Camera.set ( CV_CAP_PROP_EXPOSURE, getParamVal ( "-ss",argc,argv ) );
if ( findParam ( "-wb_r",argc,argv ) !=-1 )
Camera.set ( CV_CAP_PROP_WHITE_BALANCE_RED_V,getParamVal ( "-wb_r",argc,argv ) );
if ( findParam ( "-wb_b",argc,argv ) !=-1 )
Camera.set ( CV_CAP_PROP_WHITE_BALANCE_BLUE_U,getParamVal ( "-wb_b",argc,argv ) );
}
void showUsage() {
cout<<"Usage: "<<endl;
cout<<"[-gr set gray color capture]\n";
cout<<"[-test_speed use for test speed and no images will be saved]\n";
cout<<"[-w width] [-h height] \n[-br brightness_val(0,100)]\n";
cout<<"[-co contrast_val (0 to 100)]\n[-sa saturation_val (0 to 100)]";
cout<<"[-g gain_val (0 to 100)]\n";
cout<<"[-ss shutter_speed (0 to 100) 0 auto]\n";
cout<<"[-wb_r val (0 to 100),0 auto: white balance red component]\n";
cout<<"[-wb_b val (0 to 100),0 auto: white balance blue component]\n";
cout<<endl;
}
int main ( int argc,char **argv ) {
int fd;
int a;
int b;
if ((fd = serialOpen("/dev/ttyAMA0", 9600)) < 0)
{
fprintf(stderr, "unable to open serial device; %s\n", strerror(errno));
return 1;
}
if ( argc==1 ) {
cerr<<"Usage (-help for help)"<<endl;
}
if ( findParam ( "-help",argc,argv ) !=-1 ) {
showUsage();
return -1;
}
raspicam::RaspiCam_Cv Camera;
Camera.set(CV_CAP_PROP_FPS, 30);
processCommandLine(argc, argv, Camera);
cout << "Connecting to camera" << endl;
if (!Camera.open()) {
cerr << "Error opening camera" << endl;
return -1;
}
cout << "Connected to camera =" << Camera.getId() << endl;
cv::Mat image;
vector<Mat> Concat;
//int nCount = 70;
cout << "Capturing" << endl;
for (int i = 0; i <= 3; i++){
Camera.grab();
Camera.retrieve(image);
Concat.push_back(image.clone());
cv::imwrite("image"+std::to_string(i)+".jpg",image);
//delay(150);
}
Mat src_base, hsv_base ...