开发者

OpenCV Help on cvPerspectiveTransform

I have a problem with the follow code, i´m trying to change a perspective of an image using cvPerspectiveTransform, but I get the follow error:

OpenCV Error: Assertion failed (scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)) 


  CvMat* p = cvCreateMat(2, 4, CV_64FC1);
  CvMat* h = cvCreateMat(2, 4, CV_64FC1);
  CvMat* p2h = cvCreateMat(2, 4, CV_64FC1);

  cvZero(p);
  cvZero(h);
  cvZero(p2h);
  //set src points
  for (int i = 0; i < 4; i++) {
    CvPoint point = verifiedPoints[i];
    cvmSet( p, 0, i, point.x );
    cvmSet( p, 1, i, point.y );
    printf("point %d (%d , %d)\n",i,point.x,point.y);
  }
  //set dst points
  cvmSet( h, 0, 0, 0 );
  cvmS开发者_运维百科et( h, 1, 0, real_height );

  cvmSet( h, 0, 1, real_width );
  cvmSet( h, 1, 1, real_height );

  cvmSet( h, 0, 2, real_width );
  cvmSet( h, 1, 2, 0 );

  cvmSet( h, 0, 3, 0 );
  cvmSet( h, 1, 3, 0);

  //cvPerspectiveTransform or cvFindHomography?
  cvPerspectiveTransform(p,h,p2h);

  cvReleaseMat(&p);
  cvReleaseMat(&h);

I try to change p2h to other values, for example:

 CvMat* p2h = cvCreateMat(3, 3, CV_32F)

but I get other error:

OpenCV Error: Assertion failed (dst.type() == src.type() && dst.channels() == m.rows-1) in cvPerspectiveTransform

Any help?


According to the OpenCV documentation for cvPerspectiveTransform:

src – Source two-channel or three-channel floating-point array. Each element is a 2D/3D vector to be transformed.
dst – Destination array of the same size and type as src.
mtx – 3x3 or 4x4 floating-point transformation matrix.

So you need to declare your matrices this way:

CvMat* p = cvCreateMat(1, 4, CV_64FC2);
CvMat* h = cvCreateMat(1, 4, CV_64FC2);
CvMat* p2h = cvCreateMat(3, 3, CV_64FC1); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜