Ask Your Question

Shabrina's profile - activity

2017-08-22 06:32:06 -0500 commented question How to create polyline with mouse event

opencv version 2.4.9. coor is vector<Point2f>, src_1 is mat that contain result of median.

if I don't use setMouseCallback("Medblur",on_mouse,0); in do while, this system can't read a frame.. thanks

2017-08-21 20:36:23 -0500 asked a question How to create polyline with mouse event

I have image matrix, then The will create a polylines with right klik on mouse when I already determine the some point. this is the code.

void on_mouse(int event,int x,int y,int flags,void *ustc)
    {
        //Point pt;//mouse position;
        char coordinate[100];

        if (event == CV_EVENT_LBUTTONDOWN)
        {
            pt = Point2f(x,y);
            cout<<x<<" "<<y<<endl;
            coor.push_back(pt);
            //cout<< coor << endl;

            cv::FileStorage simpan("template.txt", cv::FileStorage::WRITE);
            cv::write(simpan,"Point",coor);
            simpan.release();

            circle(src_1,pt,3,Scalar(0,255,50),CV_FILLED,CV_AA,0);
            //src.copyTo(src);
            imshow("Medblur",src_1);
            }

        if(event==CV_EVENT_RBUTTONDOWN)
        {
            polylines(src_1,coor,false,Scalar(255,255,255),2,150,0);
        }
    }

    int main(int argc, char** argv){
    CvCapture* capture= cvCaptureFromFile("D:/Kuliah/SMT 7/TA/data/Data Input/1.avi");
    int loop=0, count=0;
    std::string suffix = ".jpg";
    IplImage* jt =NULL;
    char fname[10];

    FileStorage smp30("template.txt", cv::FileStorage::READ);
    ab[30] = smp30["Point"];
    read(ab[30],jnt[30]);
    do
    {   
        std::stringstream ss;
        jt= cvQueryFrame(capture);
        src= cv::cvarrToMat(jt);
        //src = imread("tresh.jpg",1);
        medianBlur(src,src_1,3);
        //double ai=PSNR(src,ln);
        //cout<<count<<"\t"<<ai<<"\n";
        threshold(src_1,src_2,40,130,CV_THRESH_BINARY);
        //cvtColor(src, src, COLOR_BGR2GRAY);
        imshow("Medblur",src_1);
        imshow("Thresh",src_2);
        imshow("Asli",src);
        setMouseCallback("Medblur",on_mouse,0);

        waitKey(0);
    }
    while (jt !=NULL);

}

and this is the error

OpenCV Error: Assertion failed (p.checkVector(2, CV_32S) >= 0) in cv::polylines, file ........\opencv\modules\core\src\drawing.cpp, line 2067

thanks :)) I really need help. Thank you for your attention.

2017-08-13 13:58:29 -0500 asked a question Why I can't add matrix

I have an empty matrix that name q_bar, then I will add q_bar with matrix (b_bar.mul(evec)). Evec matrix has 5 row and 5 column.
Then the system said that "no operator "+" matches these operands.

Mat rata, Qnew, yminq,q_bar, evec,etrans,b_bar, q_new,qbaru, input, y_bar;
FileStorage smp0("mall.txt", cv::FileStorage::READ);
FileStorage smp1("evecall.txt", cv::FileStorage::READ);
FileStorage smp2("a0.txt", cv::FileStorage::READ);
    ab[0] = smp0["Point"];
    ab[1] = smp1["Point"];
    ab[2] = smp2["Point"];
read(ab[0],pointz);
read(ab[1],evec);
read(ab[2],jnt[0]);

t2=t;
    t.clear();
    etrans = evec.t();
    Qnew = Mat (t2).reshape(0,5);
    yminq = Qnew - q_bar;
    b_bar = etrans.mul(yminq);
    q_new = q_bar + (b_bar.mul(evec));

I dont know why, this source code suddenly error when I move to other project.

Then I try to use add function, the system get error. this is the error

OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in cv::arithm_op, file ........\opencv\modules\core\src\arithm.cpp, line 1287

2017-07-31 04:19:36 -0500 received badge  Student (source)
2017-07-30 08:39:37 -0500 asked a question How to use Hidden Markov Model if I have just 1 data training.

How to use hidden markov model to track the heart cavity? Track the heart cavity into sistole and diastole. white polyline is the data training from keypoints.
image description

I got confused and dont know how the hidden markov model works and implementing. If you have any suggestions, What is a good method for tracking other than optical flow?

I really need your advice, because I am newbie in opencv. Thanks :))

2017-07-30 08:07:00 -0500 commented question Error 10 error C2664: 'cvGetSize' : cannot convert parameter 1 from 'IplImage' to 'const CvArr *'

thank you for your information.

2017-07-24 06:21:36 -0500 commented question Error 10 error C2664: 'cvGetSize' : cannot convert parameter 1 from 'IplImage' to 'const CvArr *'

I use opencv 2.4.9

2017-07-23 10:59:03 -0500 asked a question Error 10 error C2664: 'cvGetSize' : cannot convert parameter 1 from 'IplImage' to 'const CvArr *'

I have Matrix then I will convert to Cvarr*. this is the code

Mat src;
IplImage tmp=src, *pro_image1;
FileStorage smp0("e5.txt", cv::FileStorage::READ);
ab[0] = smp0["Point"];
int i,x,y,minX=320,maxX=0,minY=240,maxY=0;
double ri,nd=0,nt=0,out;
int A=0;
int jumRandom=10000;
CvPoint2D32f pt;
CvPoint *p;
CvMemStorage* mem_storage = NULL;
CvSeq *c=NULL;
CvSeq *first_contour = NULL;
CvPoint pt1, pt2;
read(ab[0],jnt[0]);
polylines(src, jnt[0],false,Scalar(0,0,255),2,150,0);
pro_image1 = cvCreateImage (cvGetSize(tmp), 8, 1);

and this is the error.

Error 10 error C2664: 'cvGetSize' : cannot convert parameter 1 from 'IplImage' to 'const CvArr *'

Blockquote

I dont know how to convert this. your help is very important for me :)). thanks

2017-06-21 12:26:49 -0500 asked a question Can I use good feature to track if I have the training data is a landmark point?

I have matrix that is the training data. The content of the data is point landmark. the data that save in rt matrix. then, I have new image from src matrix.

 void mean(Mat src){
    Mat rt, simpan, cascade;
    Point pt=Point2f(x,y), sm;
    FileStorage sv0("mall.txt", cv::FileStorage::READ);
    mens = sv0["Point"];
    read(mens,rt);

    Mat img_1 = rt;
    Mat img_2 = src;
  int minHessian = 400;

  SurfFeatureDetector detector( minHessian );

  std::vector<KeyPoint> keypoints_1, keypoints_2;

  detector.detect( img_1, keypoints_1 );
  detector.detect( img_2, keypoints_2 );

  //-- Step 2: Calculate descriptors (feature vectors)
  SurfDescriptorExtractor extractor;

  Mat descriptors_1, descriptors_2;

  extractor.compute( img_1, keypoints_1, descriptors_1 );
  extractor.compute( img_2, keypoints_2, descriptors_2 );

  //-- Step 3: Matching descriptor vectors using FLANN matcher
  FlannBasedMatcher matcher;
  std::vector< DMatch > matches;
  matcher.match( descriptors_1, descriptors_2, matches );

  double max_dist = 0; double min_dist = 100;

  //-- Quick calculation of max and min distances between keypoints
  for( int i = 0; i < descriptors_1.rows; i++ )
  { double dist = matches[i].distance;
    if( dist < min_dist ) min_dist = dist;
    if( dist > max_dist ) max_dist = dist;
  }

  printf("-- Max dist : %f \n", max_dist );
  printf("-- Min dist : %f \n", min_dist );

  std::vector< DMatch > good_matches;

  for( int i = 0; i < descriptors_1.rows; i++ )
  { if( matches[i].distance <= max(2*min_dist, 0.02) )
    { good_matches.push_back( matches[i]); }
  }

  //-- Draw only "good" matches
  Mat img_matches;
  drawMatches( img_1, keypoints_1, img_2, keypoints_2,
               good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
               vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

  //-- Show detected matches
  imshow( "Good Matches", img_matches );

  for( int i = 0; i < (int)good_matches.size(); i++ )
  { printf( "-- Good Match [%d] Keypoint 1: %d  -- Keypoint 2: %d  \n", i, good_matches[i].queryIdx, good_matches[i].trainIdx ); }


    //imshow("Segmentasi",src);
}

I will track the new image with the training data, but the code was be break. this is the image image description

the data training is red color. and this is the error

OpenCV Error: Assertion failed (!img.empty() && img.depth() == CV_8U) in cv::SURF::operator (), file ........\opencv\modules\nonfree\src\surf.cpp,

thank you.

2017-06-01 12:43:39 -0500 asked a question How too open video file using button click?

I have a dialog based like this.

image description

then I will, open video file using button click "Open File" then the name of file writed in edit box file name. and the video loaded in static picture, left side.

thank you :))

2017-02-03 16:01:39 -0500 received badge  Enthusiast
2017-02-02 22:20:49 -0500 asked a question How to declaration Vector ab[8] into null

I have a video frame then, I will analysis the video. This is the main code :

int main(int argc, char** argv){
CvCapture* capture= cvCaptureFromFile("D:\\data.avi");
int loop=0, count=0;
std::string suffix = ".jpg";
IplImage* jt =NULL;
char fname[10];
do
{   std::stringstream ss;
    jt= cvQueryFrame(capture);

    matframe= cv::cvarrToMat(jt);
    sprintf(fname,"%d.jpg", loop);
    cv::imwrite(fname,matframe);                            //save each frame locally
            loop++;
    ss << std::setw(1) << std::setfill('0') << count;
    std::string number = ss.str();
    std::string name = number + suffix;
    src = imread(name);
    medianBlur(matframe,src,3);
    threshold(src,src,220,255,2);
    //Canny(src,src,0,255);
    namedWindow("Frame",1);
    setMouseCallback("Frame",on_mouse,0);//mouse callback function;
    cout << coor<< endl;
    imshow("Frame",src);
        lines(src);
    waitKey(0);
    char c = cvWaitKey(1000);
    switch(c){
    case 'N' | 'n' : count++; break;
    }
}
while (jt !=NULL);

}

And this is the void lines code. This void read the data point from txt. Then, I save them into the vector jnt[8]. Then, I use this vector to get the aligment, mean, std deviation, covarian matrix, eigen vector and eigen value.

void lines(Mat src){
//int a hit=0;
Point pt;
FileStorage smp0("O0.txt", cv::FileStorage::READ);
FileStorage smp1("O1.txt", cv::FileStorage::READ);
FileStorage smp2("O2.txt", cv::FileStorage::READ);
FileStorage smp3("O3.txt", cv::FileStorage::READ);
FileStorage smp4("O4.txt", cv::FileStorage::READ);
FileStorage smp5("O5.txt", cv::FileStorage::READ);
FileStorage smp6("O6.txt", cv::FileStorage::READ);
FileStorage smp7("O7.txt", cv::FileStorage::READ);
ab[0] = smp0["Point"];
ab[1] = smp1["Point"];
ab[2] = smp2["Point"];
ab[3] = smp3["Point"];
ab[4] = smp4["Point"];
ab[5] = smp5["Point"];
ab[6] = smp6["Point"];
ab[7] = smp7["Point"];
src.copyTo(ln);
src.copyTo(align);
for(int b=0; b<8; b++){
    read(ab[b], jnt[b]);
    circle(src,pt,2,Scalar(50,0,255,50),CV_FILLED,CV_AA,0);
    polylines(ln, jnt[b],false,Scalar(255,255,0),1,150,0);
}
imshow("Before", ln);

double s60 = sin(10*M_PI /180.0);
double c60 = cos(10*M_PI /180.0);

for(int aa=0; aa<jnt[3].size(); aa++){
    ar = jnt[1].at(aa);
    arr = jnt[0].at(aa);
    arrr = jnt[2].at(aa);
    arr2 = jnt[3].at(aa);
    ar.x =  c60 * (arr.x - ar.x) - s60 * (arr.y - ar.y) + ar.x;
    ar.y =  s60 * (arr.x - ar.x) + c60 * (arr.y - ar.y) + ar.y;
    arrr.x =  c60 * (arr.x - arrr.x) - s60 * (arr.y - arrr.y) + arrr.x;
    arrr.y =  s60 * (arr.x - arrr.x) + c60 * (arr.y - arrr.y) + arrr.y;
    arr2.x =  c60 * (arr.x - arr2.x) - s60 * (arr.y - arr2.y) + arr2.x;
    arr2.y =  s60 * (arr.x - arr2.x) + c60 * (arr.y - arr2.y) + arr2.y;

    oi.push_back(arr);
    anyar.push_back(ar);
    ac.push_back(arrr);
    ay.push_back(arr2);

    polylines(align, oi, false, Scalar(100,150,150),1, 8);
    polylines(align, anyar, false, Scalar(0,150,150),1, 8);
    polylines(align, ac, false, Scalar(125,150,150),1,8);
    polylines(align, ay, false, Scalar(200,0 ...
(more)
2017-01-27 03:18:40 -0500 commented answer How to save matrix 2d to array

thank you, for your answer. That's very helpful

2017-01-27 03:17:13 -0500 received badge  Scholar (source)
2017-01-27 03:05:50 -0500 commented question How to save matrix 2d to array

yes, I wan to merge this 2 matrices

2017-01-27 01:28:53 -0500 asked a question How to save matrix 2d to array

I have 2 matrix, egnvecx and egnvecy. egnvecx :

[0.52065742, 0.39711261, 0.75578946, 0;
  -0.42713234, 0.88765043, -0.17214788, 0;
  0, 0, 0, 1;
  0.73923874, 0.233192, -0.63178128, 0]

egnvecy :

[1, 0, 0, 0;
  0, 1, 0, 0;
  0, 0, 1, 0;
  0, 0, 0, 1]

Then, I will save this matrix into array it contain x and y. But I dont know how the step is. this the code will be error.

Mat data_pts = Mat(4,4, CV_32F);
    for (int i = 0; i < data_pts.rows; ++i)
    {
        for (int x=0; x<data_pts.cols; x++){
            data_pts.at<float>(i,x) = egnvecx.ptr<float>(i,x);  
            data_pts.at<float>(i,x) = egnvecy.ptr<float>(i,x);  
        }
    }
    cout << data_pts;

thank you :))

2017-01-25 22:20:25 -0500 asked a question how to create matrix nxn to 2nx2n ?

I have Matrix 4x4 like this

[0, 0, 0, 0, 0.5, 0, 0, 0; 0, 0, 0.25, 0, 0.25, 0, 0, 0; 0.5, 0, 0.25, 0, 0.25, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0]

every column contais x and y. Then I will change this matrix to matrix 2nx2n. But I dont know how the step is. Please help me. Thank you :))

2017-01-21 22:24:37 -0500 commented answer How can I reshape matrix 1xn to matrix sqrt(n)xsqrt(n) ?

Thank you the problem was solved, I get the misplace to initialize yesterday. Thank you for your attention :))

2017-01-21 21:39:07 -0500 asked a question Mat operation

I have vector ay[4] , then I get the mean of vector. So, I change the vector to matrix. like this

Mat total,rata;
total =  Mat(ay[1]) + Mat(ay[2]) + Mat(ay[3]);
rata = total/3;
cout <<"Total"<< total << endl;
cout <<"Rata"<< rata << endl;

Then, I use the mean of matrix for get the deviation, this is the code.

Mat dev[4], chg[4];
for (int abc=0; abc<4; abc++){
    chg[abc] = Mat(ay[abc]);
}
for(int s=0; s<4;s++){
    cv::subtract(chg[s],rata,dev[s]);
}
cout << "Data" << dev[1] << endl;

when, I operation this code. the program was break. and this is the error

OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in cv::arithm_op, file ........\opencv\modules\core\src\arithm.cpp, line 1287

I dont know why, but that are have the same initialization. Thanks.

2017-01-20 21:45:22 -0500 asked a question Calculate Eigen Vector and Eigen Value for PCA

I want to get eigenvalue and eigenvector. But it breaks. this is my part of code.

Mat covmat=((matdev*matdev.t())/3); //data float matrix 5*5, this's working. but when I add with PCA function. It's break.
PCA pt_pca(covmat, Mat(), CV_PCA_DATA_AS_ROW, 0);
            Mat pt_eig_vals = pt_pca.eigenvalues;
            for (int i = 0; i < 4; ++i)
            cout << pt_eig_vals.at<float>(i, 0) <<endl;

This is the error. OpenCV error: Assertion Failed <data.channerls&lt;&gt; =="1"> in unknown function, file ......\src\opencv\modules\core\src\matmul.cpp

Please somebody help me :(. Thanks

2017-01-20 08:04:50 -0500 commented answer How can I reshape matrix 1xn to matrix sqrt(n)xsqrt(n) ?

I just trying these code but the program still break.

2017-01-20 06:50:38 -0500 received badge  Editor (source)
2017-01-20 06:49:42 -0500 asked a question How can I reshape matrix 1xn to matrix sqrt(n)xsqrt(n) ?

I have matrix 1x16. I will reshape this matrix to 4x4. How can I reshape this matrix? I just use this code, but the program was break.

//transpose 
    Mat det0 = Mat(d1);
    Mat dt1;
    dt1 = det0.reshape(0,4);
    cout << " Sebelum transpose "<<det0 <<endl;
    cout << "coba" << dt1 <<endl;

`