Created
July 16, 2018 07:54
-
-
Save saccadic/f116daaf191a1c94b5f3af7174f9afb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "ofMain.h" | |
| #include "ofxOpenCv.h" | |
| inline void toOf(const cv::Mat &src, ofImage &img){ | |
| ofPixels pix; | |
| pix.setFromExternalPixels(src.data,src.cols,src.rows,src.channels()); | |
| img.setFromPixels(pix); | |
| img.update(); | |
| } | |
| inline void toOf(const cv::Mat &src, ofPixels &pix){ | |
| pix.setFromExternalPixels(src.data,src.cols,src.rows,src.channels()); | |
| } | |
| template <class T> | |
| inline cv::Mat toCv(ofBaseHasPixels_<T> &img){ | |
| return toCv(img.getPixels()); | |
| } | |
| template <class T> | |
| inline cv::Mat toCv(ofPixels_<T> &pix){ | |
| static int depth; | |
| static int channel; | |
| switch(pix.getBytesPerChannel()){ | |
| case 4: | |
| depth = CV_32F; | |
| break; | |
| case 2: | |
| depth = CV_16U; | |
| break; | |
| case 1: | |
| depth = CV_8U; | |
| break; | |
| } | |
| channel = pix.getNumChannels(); | |
| return cv::Mat(pix.getHeight(), pix.getWidth(), CV_MAKETYPE(depth,channel),pix.getData(),0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment