I have a std::vector<uchar>
which contains pixel values calculated from somewhere else. Now I want to convert this to a Mat
type and show it. But I faced some problems...only some part of the resulted image looks find and the rest seems to be corrupted. Can you please tell me what am I doing wrong? Here is my code:
void convertMeanVectorToImageAndShow(cv::Size size, int type
, PedRec::mean_vector *vector
, QString windowName) {
cv::Mat mat;
mat.create(size.height, size.width, type);
int rows = mat.rows;
int cols = mat.cols;
if (mat.isContinuous()) {
cols = rows*cols;
rows = 1;
}
for (int r = 0; r < rows; ++r)
{
uchar *pOutput = mat.ptr<uchar>(r);
for (int c = 0; c < cols; ++c)
{
*pOutput = (uchar)vector->at(c);
++pOutput;
}
}
cv::imshow(windowName.toStdString(), mat);
}