Ask Your Question
0

'type' undeclared identifier opencv traits.hpp

asked 2020-05-28 14:36:30 -0500

albeh95 gravatar image

updated 2020-05-28 15:37:20 -0500

Hi all, I've got this error in the function: "calcOpticalFlowPyrLK". Basically I have to track a book from a video given, do I used SIFT features to detect the book in the video and surrounding it with a square obtaining the following result: image description Then I have to track (and show) the features of the book using the pyramid Lukas-Kanade tracker, and I'm using the following code:

           for (;;) {
            //tracking

            vector<uchar> status;
            vector<float> err;
            vector<KeyPoint> next_keypoints;
            Mat result;
            if (prev_gray.empty())
            {
                gray.copyTo(prev_gray);
            }
            cap >> frame;
            cvtColor(frame, gray, COLOR_BGR2GRAY);
            calcOpticalFlowPyrLK(prev_gray, gray, keypoints_2, next_keypoints, status, err);
            drawKeypoints(prev_gray, keypoints_2, result);
            imshow("res", result);
            gray.copyTo(prev_gray);
            keypoints_2 = next_keypoints;

        }

Where "prev_gray" is an empty Mat defined at the beginning of the code (before of the SIFT obj detection), "gray" is the first frame of the video converted in gray scale and keypoints_2 is the vector<keypoint> of the first frame of the video.

At the execution of the method "calcOpticalFlowPyrLK(prev_gray, gray, keypoints_2, next_keypoints, status, err);", I'm getting the error "type: udeclared identifier (at traits.hpp)" and "type is not a member of 'cv::DataType<t>'"

What could be the problem? Thank y'all!

EDIT: Following break suggestion, I changed my code into:

                    vector<KeyPoint> next_keypoints1;
        vector<uchar> status;
        vector<float> err;
        vector<Point2f> next_keypoints;
        vector<Point2f> keypoints_frame_temp;
        vector<KeyPoint> keyponts_frame;
        for (;;) {
            //tracking

            KeyPoint::convert(keypoints_2, keypoints_frame_temp);
            Mat result;
            if (prev_gray.empty())
            {
                gray.copyTo(prev_gray);
            }
            cap >> frame;
            cvtColor(frame, gray, COLOR_BGR2GRAY);
            calcOpticalFlowPyrLK(prev_gray, gray, keypoints_frame_temp, next_keypoints, status, err);
            KeyPoint::convert(keypoints_frame_temp, keyponts_frame);
            drawKeypoints(prev_gray, keyponts_frame, result);
            imshow("res", result);
            gray.copyTo(prev_gray);
            KeyPoint::convert(next_keypoints, next_keypoints1);
            keyponts_frame = next_keypoints1;

        }

Using the KeyPoint::convert function to have the right type inside the calcOpticalFlowPyrLK(), but what I get in the "res" windows is just a blank space and I have no access to it (I can see the window, but I can't do anything on it). Is it a problem of my pc? Is it maybe not powerful enough for this?

edit retag flag offensive close merge delete

Comments

1

imshow() only works with a following waitKey(), look it up.

berak gravatar imageberak ( 2020-05-28 15:42:00 -0500 )edit

thanks! now it's working!

albeh95 gravatar imagealbeh95 ( 2020-05-28 16:06:31 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-05-28 15:14:06 -0500

berak gravatar image

What could be the problem?

vector<KeyPoint> next_keypoints;

is not an appropriate input for "next_points" in calcOpticalFlowPyrLK()

it expects vector<Point> as input, if you want to use SIFT keypoints for this, you'll have to make a loop, copying the Keypoint::ptmember into a seperate vector, and use that for optflow

edit flag offensive delete link more

Comments

1

Thank you berak you're always the best here! I followed your suggestion and I used the KeyPoint::convert function to have the right type. Actually it's still not working, I've edited my question. Am I suppose to open a new thread for that?

albeh95 gravatar imagealbeh95 ( 2020-05-28 15:38:30 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-05-28 14:36:30 -0500

Seen: 50 times

Last updated: May 28