Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings

Browse | Submit A New Snippet | Create A Package

 

FCam::Image to OpenCV cv::Mat

Type:
Function
Category:
Other
License:
GNU General Public License
Language:
C++
 
Description:
Converts an FCam image to an OpenCV cv::Mat.

Versions Of This Snippet::

Sebastian Koch
Snippet ID Download Version Date Posted Author Delete
220.32012-05-15 13:59Sebastian Koch
Changes since last version::
removed class name
210.22012-05-15 13:59Sebastian Koch
Changes since last version::
returning NULL was bad, just removed error checking
200.12012-05-15 13:43Sebastian Koch

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :0.3

cv::Mat fcam_to_cv(const FCam::Image im)
{
    // expects an UYVY image

    int width = im.width();
    int height = im.height();

    cv::Mat src = cv::Mat(height, width * 2, CV_8UC1).reshape(2);

    for (int y=0;y<src.rows;y++){
        cv::Vec2b* r = src.ptr<cv::Vec2b>(y);
        for (int i=0; i<src.cols; i = i+2){
            // fancy stuff to get the correct colors
            r[i] = cv::Vec2b(im(i+1,y)[0],im(i,y)[1]);
            r[i+1] = cv::Vec2b(im(i,y)[0],im(i+1,y)[1]);
        }
    }
    cv::Mat img = cv::Mat(height, width * 3, CV_8UC1).reshape(3);

    cv::cvtColor(src,img,cv::COLOR_YUV2RGB_UYVY,-1);

    return img;
}

		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..


Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment