Skip to content

cvtColorTwoPlane gives wrong output when Y Plane Mat has step #17036

@coroner4817

Description

@coroner4817
System information (version)
  • OpenCV => 4.3
  • Operating System / Platform => MacOS
  • Compiler => AppleClang 11.0.0.11000033
Detailed description

when using cvtColorTwoPlane, and Y plane Mat has stride, the output image is wrong. However if I use a Mat with the same data but no stride, I get correct result.
However, the uv_plane Mat does work with/without stride.

Steps to reproduce
cv::Mat rmPadding(cv::Mat in)
{
  cv::Mat out = cv::Mat::zeros(in.rows, in.cols, CV_8UC1);
  uint8_t* p1 = in.ptr<uint8_t>(0);
  uint8_t* p2 = out.ptr<uint8_t>(0);

  for(int i = 0; i < in.rows; i++){
    for(int j = 0; j < in.cols; j++){
      p2[i * in.cols + j] = p1[i * in.step + j];
    }
  }
  return out;
}

// not working!!!
cv::Mat y_plane_padding(1080, 1920, CV_8UC1, y_plane_data.data(), 2048);
// working!
cv::Mat y_plane_nopadding = rmPadding(y_plane_padding);
...
cv::cvtColorTwoPlane(y_plane_nopadding, uv_plane, rgb_image, cv::COLOR_YUV2RGB_NV21);

Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    answers.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    Hackathonhttps://opencv.org/opencv-hackathon-starts-next-week/bugcategory: imgprocconfirmedThere is stable reproducer / investigation completefeature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions