Openmvg: How to use with OpenCV?

Created on 15 Apr 2017  路  6Comments  路  Source: openMVG/openMVG

I want to convert cv::Mat to openMVG::Image.

Is there a non-const openMVG::Image.getMat() that I could use in:

cv::cv2eigen(cv::Mat, openMVG::Image.something())

EDIT: To give a bit more info, the image source in my program is an openFrameworks ofImage, which I can convert to cv::Mat or get the unsigned char array of pixels directly.

So basically what I'm looking for is an internal (not from a file) interface to set openMVG images

Most helpful comment

Thanks! Worked exactly how you said with a resize function - never would've figured it out myself

    cv::Mat cv_image;
    ....
    Image<uint8_t> mvg_image;
    mvg_image.resize(cv_image.cols, cv_image.rows);
    cv::cv2eigen(cv_image, *(Image<uint8_t>::Base*)&mvg_image);

All 6 comments

Hi @itsdsk
The following must work

        cv::Mat image_cv;
        image_cv = cv::imread( sView_filename, CV_LOAD_IMAGE_GRAYSCALE );
        Image<uint8_t> image_openmvg;
        cv::cv2eigen(image_cv, *(Image<uint8_t>::Base*)&image_openmvg);

Thanks! Worked exactly how you said with a resize function - never would've figured it out myself

    cv::Mat cv_image;
    ....
    Image<uint8_t> mvg_image;
    mvg_image.resize(cv_image.cols, cv_image.rows);
    cv::cv2eigen(cv_image, *(Image<uint8_t>::Base*)&mvg_image);

Please close the issue if you don't have other point(s) to comment.

Just stating the obvious, but for that to work the cv::Mat object has to have CV_8UC1 as its scalar type.

What if I want to use it with RGB image ?

@a-mohsen

Please open a new issue since the thread you opened is more than 1 year old and your question is not directly related to this issue (and may be interesting for the community).

Was this page helpful?
0 / 5 - 0 ratings