-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Invalid example in cv::Mat documentation #19131
Copy link
Copy link
Closed
Labels
affected: 2.4EOL - not supported anymoreEOL - not supported anymorebugcategory: corecategory: documentationDocumentation fix or updateDocumentation fix or update
Milestone
Description
From at least 3.4 to the current master build, an invalid example has been present in the cv::Mat documentation (https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html):
- Make a header for user-allocated data. It can be useful to do the following:
- Process "foreign" data using OpenCV (for example, when you implement a DirectShow* filter or a processing module for gstreamer, and so on). For example:
void process_video_frame(const unsigned char* pixels, int width, int height, int step) { Mat img(height, width, CV_8UC3, pixels, step); GaussianBlur(img, img, Size(7,7), 1.5, 1.5); }
This example has two problems:
- It's not possible, as
pixelsisconstbut there is no constructor forMatwhich takes aconstdata pointer. - It's broken, as the call to
GaussianBlurindirectly modifiespixelswhich the caller assumed to beconst.
The easiest fix is to just remove the const from pixels in the example.
The wrong fix, if anybody is tempted, is to add const_cast because of point 2.
The practical fix, which also defeats the purpose of the example (and renders the example function useless):
Mat img(height, width, CV_8UC3);
for (int row = 0; row < height; ++ row)
memcpy(img.ptr(row), pixels + (row * step));
The fantasy fix is to work some template magic to allow Mat_<const unsigned char> to exist.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
affected: 2.4EOL - not supported anymoreEOL - not supported anymorebugcategory: corecategory: documentationDocumentation fix or updateDocumentation fix or update