Ask Your Question

jason's profile - activity

2017-11-29 22:36:39 -0600 received badge  Notable Question (source)
2017-04-19 05:19:58 -0600 received badge  Popular Question (source)
2016-09-05 12:32:20 -0600 commented question How to define a matrix with 5000 specific elements

Thank you. I will learn how to do it.

2016-09-05 12:18:14 -0600 commented question How to define a matrix with 5000 specific elements

Thank you. It worker. How stupid I was, forgot to change the data type. When I say"it's not regular", I mean that it's not random number, nor part a a progression, so I can't define it in a loop. I am not a native English speaker. So I may make mistakes. Anyway, thank you very much.

2016-09-05 12:04:25 -0600 asked a question How to define a matrix with 5000 specific elements

Hello, I need to define a matrix M, M is 5000*2. In matlab, M=[1,45;89,3;....], it's not regular, so I can't define it in a loop. In my code I tried to define it like

Mat M = (Mat_<int>(num, 3) << 994, 323, 0, 4014, 4295, 4395, 4906, 3423, 2792.....);

But when I use printf("number: %f", M.at<double>(2, 1), it gives me 0. So could anyone tell me how to define such a matrix like in matlab M=[1 2 3; 4 5 6;....]

2016-02-19 14:04:19 -0600 commented answer How to imwrite an image to a certain folder

Thanks for your reply first. If I create a new folder named 'Image folder', how could I imwrite the images into this folder? Assume the directory of this folder is 'C:\Users\jasonz\Desktop'

2016-02-18 21:19:12 -0600 asked a question How to imwrite an image to a certain folder

Hello, Could anyone tell me how to use imwrite to write the images into a certain folder(better to create a new folder when run the code). And I will write many images to this folder, hope the new written image will not overwrite the previous one. Thanks

2016-01-24 16:27:12 -0600 commented question pixel intensity are different from opencv to matlab

Hi, berak, I made a mistake before using cv:Rect So I didn't crop the image as desired. Thanks for your input.

2016-01-22 18:39:40 -0600 asked a question pixel intensity are different from opencv to matlab

Hello, I am trying to convert matlab code to c++ code with opencv. And it's killing me..... The pixel intensity of the same image is different between opencv and matlab. The code used in opencv to printf pixel intensity:

    Mat img1 = imread("image1.jpg");
    Mat gray_image1;
    cvtColor(img1, gray_image1, CV_BGR2GRAY); //searched that imread in opencv read as BGR sequence
    int Height = gray_image1.rows;
    int Width = gray_image1.cols;
     for(int m=0;m<H;m++){
         for(int n=0;n<W;n++){
           printf("%d",gray_image1.at<uchar>(m,n));
        //or printf("%f",gray_image1.at<float>(m,n)); 
    }
    printf("\n");
    }

and the code used in matlab

Im1=imread("image1.jpg");

and in matlab just set a break point to see the pixel intensity of Im1. The difference between the same pixel is large. For example, the last pixel is about 180 in opencv while it is 200 in matlab. Could anyone tell me how to solve this problem? And what's the datatype of gray_image1 pixel in my code? float or int? And how t convert it into float to improve the accuaracy.

2016-01-21 21:46:07 -0600 asked a question Error on pixel manipulation

Hello, I am manipulating pixel with opencv in raspberry pi. There is something wrong with the attached code. I can compile it. But when I run it on the raspberry pi. It report "Bus error". I can't run it with visual stdio either. Could anyone told me how to solve it? smallIm1 and smallIm2 are the two images I need to process. Thank you

for (int m = 0; m < Height - 1; m++){
    for (int n = 0; n < Width - 1; n++){
        Ix.at<double>(m, n) = (smallIm1.at<double>(m + 1, n) - smallIm1.at<double>(m, n) + smallIm1.at<double>(m + 1, n + 1) - smallIm1.at<double>(m, n + 1) + smallIm2.at<double>(m + 1, n) - smallIm2.at<double>(m, n) + smallIm2.at<double>(m + 1, n + 1) - smallIm2.at<double>(m, n + 1)) / 4;
        Iy.at<double>(m, n) = (smallIm1.at<double>(m, n + 1) - smallIm1.at<double>(m, n) + smallIm1.at<double>(m + 1, n + 1) - smallIm1.at<double>(m + 1, n) + smallIm2.at<double>(m, n + 1) - smallIm2.at<double>(m, n) + smallIm2.at<double>(m + 1, n + 1) - smallIm2.at<double>(m + 1, n)) / 4;
        It.at<double>(m, n) = (smallIm2.at<double>(m, n) - smallIm1.at<double>(m, n) + smallIm2.at<double>(m + 1, n) - smallIm1.at<double>(m + 1, n) + smallIm2.at<double>(m, n + 1) - smallIm1.at<double>(m, n + 1) + smallIm2.at<double>(m + 1, n + 1) - smallIm1.at<double>(m + 1, n + 1)) / 4;
        G.at<double>(m, n)  = (m + 1)*Ix.at<double>(m, n) + (n + 1)*Iy.at<double>(m, n);
        sumA00 = Ix.at<double>(m, n) * Ix.at<double>(m, n) + sumA00; sumA01 = Ix.at<double>(m, n) * Iy.at<double>(m, n) + sumA01;  sumA02 = Ix.at<double>(m, n) * G.at<double>(m, n) + sumA02;
        sumA10 = Ix.at<double>(m, n) * Iy.at<double>(m, n) + sumA10; sumA11 = Iy.at<double>(m, n) * Iy.at<double>(m, n) + sumA11;  sumA12 = Iy.at<double>(m, n) * G.at<double>(m, n) + sumA12;
        sumA20 = Ix.at<double>(m, n) * G.at<double>(m, n)  + sumA20; sumA11 = G.at<double>(m, n)  * Iy.at<double>(m, n) + sumA21;  sumA12 = G.at<double>(m, n)  * G.at<double>(m, n) + sumA22;
        sumB00 = Ix.at<double>(m, n) * It.at<double>(m, n) + sumB00; sumB10 = Iy.at<double>(m, n) * It.at<double>(m, n) + sumB10;  sumB20 = It.at<double>(m, n) * G.at<double>(m, n) + sumB20;
    }
}
2016-01-18 11:13:27 -0600 commented answer How to define a function using image as the input argument

Thank you very much

2016-01-17 18:27:24 -0600 asked a question How to define a function using image as the input argument

Hello, I am new to opencv so I ask a simple question. I want to define a function using the image as the input argument. How should I define it? Likevoid compute(int a , char b). If the image is named Im1, could I define it like void compute(cv:Mat Im1, int a )? Thanks for your help

2015-12-05 15:12:23 -0600 received badge  Enthusiast
2015-12-04 19:02:41 -0600 received badge  Scholar (source)
2015-12-04 19:02:34 -0600 commented answer error about cvtColor

Yes, it worker. Thank you very much, now I can finish my final project. Thank you!

2015-12-02 21:38:08 -0600 received badge  Editor (source)
2015-12-02 21:32:57 -0600 asked a question 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 ...
(more)
2015-12-02 20:28:26 -0600 asked a question How to load pictures taken in the same code

Hello, I am doing a project to take pictures and then compare them. I use combine the raspicam_cv_test.cpp and compareHist_Demo.cpp on raspberry pi. Followed 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 &amp;&amp;="" idx="=-1;" i++="" )="" if="" (="" string="" (="" argv[i]="" )="=param" )="" idx="i;" return="" idx;<="" p="">

} //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 &amp;&amp;="" idx="=-1;" i++="" )="" if="" (="" string="" (="" argv[i]="" )="=param" )="" idx="i;" if="" (="" idx="=-1" )="" return="" defvalue;="" else="" return="" atof="" (="" argv[="" idx+1]="" );="" }<="" p="">

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&lt;&lt;"[-gr="" set="" gray="" color="" capture]\n";="" cout&lt;&lt;"[-test_speed="" use="" for="" test="" speed="" and="" no="" images="" will="" be="" saved]\n";="" cout&lt;&lt;"[-w="" width]="" [-h="" height]="" \n[-br="" brightness_val(0,100)]\n";="" cout&lt;&lt;"[-co="" contrast_val="" (0="" to="" 100)]\n[-sa="" saturation_val="" (0="" to="" 100)]";="" cout&lt;&lt;"[-g="" gain_val="" (0="" to="" 100)]\n";="" cout&lt;&lt;"[-ss="" shutter_speed="" (0="" to="" 100)="" 0="" auto]\n";="" cout&lt;&lt;"[-wb_r="" val="" (0="" to="" 100),0="" auto:="" white="" balance="" red="" component]\n";="" cout&lt;&lt;"[-wb_b="" val="" (0="" to="" 100),0="" auto:="" white="" balance="" blue="" component]\n";<="" p="">

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="" &lt;&lt;="" "connecting="" to="" camera"="" &lt;&lt;="" endl;="" if="" (!camera.open())="" {="" cerr="" &lt;&lt;="" "error="" opening="" camera"="" &lt;&lt;="" endl;="" return="" -1;="" }="" cout="" &lt;&lt;="" "connected="" to="" camera ... (more)

2015-11-28 22:41:09 -0600 asked a question using opencv to compare images on raspi

Hello, Now I want to using the example code from http://docs.opencv.org/2.4/doc/tutori... on my raspberry to do some image comparison. I have installed opencv 2.4.10 on raspberry pi. When I tried to incorporate the code with the one I download here http://sourceforge.net/projects/raspi... (raspicam-0.1.3/utils/raspicam_cv_test.cpp). There is some error to compile it. "fatal error: opencv2/imgcodecs.hpp: No such file or directory" So how could I solve this problem? I think it is because I didn't put three hpp files in the right directory:

include "opencv2/imgcodecs.hpp"

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

I download the whole zip file given here https://github.com/Itseez/opencv. And put in /raspicam-0.1.3/src/opencv2 . I also put the other files required by the compiler. But when I compile it again, it told me "cv::imwrite undifined". If I don't do the steps I mentioned above, I can use cv:imwrite. So could anyone tell mewhich directory should I put them in. Thanks! Regards

2015-11-28 22:41:08 -0600 asked a question Using opencv on raspberry pi

Hello, Now I want to using the example code from http://docs.opencv.org/2.4/doc/tutori... on my raspberry to do some image comparison. I have installed opencv 2.4.10 on raspberry pi. When I tried to incorporate the code with the one I download here http://sourceforge.net/projects/raspi... (raspicam-0.1.3/utils/raspicam_cv_test.cpp). There is some error to compile it. "fatal error: opencv2/imgcodecs.hpp: No such file or directory" So how could I solve this problem? I think it is because I didn't download the three hpp file:

include "opencv2/imgcodecs.hpp"

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

I download the whole zip file given here https://github.com/Itseez/opencv. But I didn't find them. So could anyone tell me where could I find these files and which directory should I put them in. Thanks! Regards