加载和显示视频的OpenCV会产生不准确的颜色

时间:2012-06-27 10:42:55

标签: opencv

我按照OpenCV中给出的视频显示示例,只是为我做了一些不必要的转换。我现在的代码加载视频文件,然后显示它,问题是再现的视频有错误的颜色。

以下是代码:

using namespace std;
using namespace cv;

// The main function

int main (int argc, char *argv[])
{

VideoCapture cap ("ETMI 002.mpg");  // Open the file

if (!cap.isOpened ())               // Check if opening was successful
    cerr << "I have failed!" << endl;

else
{
    Mat edges;
    Mat frame;
    namedWindow("edges",1);
    while (cap.read (frame))
    {
      cvtColor(frame, edges, CV_BGR2RGB);  
      imshow("edges", edges);
      if(waitKey(30) >= 0) break;
    }
}

return 0;

}

1 个答案:

答案 0 :(得分:0)

避免转载视频转换中的转换
imshow(“edge”,edges
imshow(“edge”,frame

while (cap.read (frame))
{
  cvtColor(frame, edges, CV_BGR2RGB); 

  // here is the change you are showing the converted image 
  // just simply add the original read frame

  imshow("edges", frame);   // here 
  if(waitKey(30) >= 0) break;
}