Hello, I was trying to somehow access my pixels in opencv 2. For this, I defined the following pixel structure:
struct mypixels { unsigned char red; unsigned char green; unsigned char blue; };
Now I tried the following and it works:
int sz[3] = {2,2}; cv::Mat XL(2,sz, CV_8UC3, cv::Scalar::all(0)); cv::Mat_<cv::Vec3b> pixiter = XL; pixiter.at<mypixels>(0,0).green = 22;
Now this code works well in release mode, but in debug mode I get some access violation error. I did not try to hack or rewrite opencv classes. I just donβt understand what I have to do to make this code work in release and debug mode. I thought, maybe I need to determine my pixels, as it is written here: http://docs.opencv.org/trunk/modules/core/doc/basic_structures.html#datatype But I could not understand how and what I should do here. Maybe here is someone who knows more.
- EDIT -
Using the working solution user2151446 and some extra brain power, I came up with this solution:
template<> class cv::DataType<mypixels> { public: typedef mypixels value_type; typedef int work_type; typedef unsigned char channel_type; typedef value_type vec_type; enum { depth = CV_8U, channels = 3, type = CV_MAKETYPE(depth, channels), fmt=(int)'u' }; };
source share