2

我按照 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;

}

4

1 回答 1

0

为避免在复制视频
中将 imshow("edges", edges) 转换为
imshow("edges", 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;
}
于 2012-06-27T11:29:50.743 回答