2014-01-23 74 views
1

我正在尝试使用imread读取OpenCV C++中的图像。这里的问题是图像的文件名。文件名包含一个.dot文件名。例如这里是名称的一个示例:从.txt列表中读取图像

00006.jpg0.jpg 

怎么可能读这样一个形象? 矢量文件;

 string line; 
     ifstream myfile ("Anny.txt"); 
     if (myfile.is_open()) 
     { 
     while (getline (myfile,line)) 
     { 
      cout << line << '\n'; 
      files.push_back(line); 
      string img ="db/video/"+line; 
      cout << img<< endl; 
      string dest = "db/video1/"+line; 
      Mat image = imread(img,1); 

      cout << image.rows << " " << image.cols << endl; 
      imshow("new", image); 
      waitKey(0); 
      imwrite(dest, image); 

     } 

     myfile.close(); 
     } 

编辑︰基本上错误在于getline,但我没有得到它。当我更改img文件而不是+行时,将来自终端imshow的打印字符串和imread的作用像魅力一样。

+0

这里没问题。甚至没有'my.png.jpg' – berak

+0

'cv :: Mat image = cv :: imread(“00006.jpg0.jpg”);'对我来说工作正常 – Micka

+0

看来,当我读它时,它会返回一个空的垫子文件。当我试图在imshow中显示结果时,我得到: OpenCV错误:断言失败(size.width> 0 && size.height> 0)在imshow中,文件/home/christosh/Desktop/OpenCV/opencv-2.4。 7/modules/highgui/src/window.cpp,第269行 在抛出'cv :: Exception'实例后终止调用什么():/home/christosh/Desktop/OpenCV/opencv-2.4.7/modules/ highgui/src/window.cpp:269:error:(-215)size.width> 0 && size.height> 0在函数imshow中 –

回答

4

按照docsimread

... determines the type of an image by the content, not by the file extension.

如果您收到一个错误,它并不适合你所承担的原因,它是。你需要更好地调查你所看到并没有告诉我们的事情。

+0

耻辱对我来说,你是对的! –

4

好吧我改变了我阅读txt文件的方式,一切正常。而不是getline我使用infile和一切正在工作。

ifstream infile("Anny.txt"); 
    string line; 
    while(infile>> line){ 
     string img ="db/video/"+line; //db/video/00006.jpg0.jpg 
     cout << img<< endl; 
     string dest = "db/video1/"+line; 
     Mat image = imread(img,1); 

     cout << image.rows << " " << image.cols << endl; 
     imshow("new", image); 
     waitKey(0); 
     imwrite(dest, image); 
    }