Ask Your Question

cout'ing a CvPoint2D32f variable

asked 2013-07-30 01:14:39 -0600

thevidyy gravatar image

updated 2013-07-30 01:19:11 -0600

#include <iostream>
using namespace std;
int main(int argc, char** argv)
    CvPoint2D32f test = cvPoint2D32f(12,12);
    cout << test << endl;

Anyone know why I can't cout test in my code above? And what's the difference between defining test as above and defining it like CvPoint2D32f test = new CvPoint2D32f[144]? Thanks.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-07-30 01:21:05 -0600

tenta4 gravatar image

updated 2013-07-30 01:25:00 -0600

You must to use c++ version
CvPoint2D32f test = cvPoint2D32f(12,12);
cv::Point2f testCpp(test);
std::cout << testCPP << std::endl;

edit flag offensive delete link more


Agreed, drop the C-style API, it gets you more errors than you can imagine :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-30 02:02:14 -0600 )edit

Exactly which part of my code is "C-style'? Sorry, I'm a little new to this.

thevidyy gravatar imagethevidyy ( 2013-07-30 09:38:32 -0600 )edit

All parts of your code, containing the Cv caption in front of the function name, says that you are using old OpenCV 1.x C-style types. They have been changed to corresponding C++ style types like illustrated above.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-30 09:42:23 -0600 )edit

How can I do the same with a matrix (say, ouputting the identity matrix [1 0 0; 0 1 0; 0 0 1] on the screen.) Using the method above doesn't work:

CvMat* test = cvCreateMat(3,3,CV_32FC1); //empty matrix

cv::Mat2f testx(*test);

cout << testx << endl;

And regarding the C-style API, are you saying I'm better off doing something like: using namespace cv; waitKey(0);

rather than cvWaitKey(0);?

thevidyy gravatar imagethevidyy ( 2013-07-30 11:06:12 -0600 )edit

Just use the Mat operator instead of CvMat, which can be put into cout directly.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-30 11:51:35 -0600 )edit

If I use Mat, I won't be able to set the values of the elements in the matrix, i.e. cvSetReal2D(CvArr* arr, int idx0, int idx1, double value). Is there any other way I can set the values of the matrix using the Mat operator?

thevidyy gravatar imagethevidyy ( 2013-07-30 12:34:58 -0600 )edit

please put some effort in reading the docs ... I just pointer you to the Mat class which has an operator called at<type>(x,y) and if you read further, you can even see that there is a Mat_ type which can be adressed by simple using [x,y].

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-30 12:46:27 -0600 )edit

Question Tools


Asked: 2013-07-30 01:14:39 -0600

Seen: 357 times

Last updated: Jul 30 '13