2012-08-11 58 views
2

我在Visual Studio 2012上運行OpenCV 2.4.2。我想使用MSER檢測圖像中的文本。我開始了與在OpenCV的目錄中提供的樣本MSER示例程序,MSER在Visual Studio 2012中的OpenCV 2.4.2中的示例

#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/features2d/features2d.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
#include <iostream> 
#include <stdio.h> 

using namespace cv; 
using namespace std; 

static const Vec3b bcolors[] = 
{ 
    Vec3b(0,0,255), 
    Vec3b(0,128,255), 
    Vec3b(0,255,255), 
    Vec3b(0,255,0), 
    Vec3b(255,128,0), 
    Vec3b(255,255,0), 
    Vec3b(255,0,0), 
    Vec3b(255,0,255), 
    Vec3b(255,255,255) 
}; 

int main(int argc, char** argv) 
{ 
    string path; 
    Mat img0, img, yuv, gray, ellipses; 

    img0 = imread(argc != 2 ? "puzzle.png" : argv[1], 1); 
    if(img0.empty()) 
    { 
     if(argc != 2) 
      cout << "\nUsage: mser_sample <path_to_image>\n"; 
     else 
      cout << "Unable to load image " << argv[1] << endl; 
     return 0; 
    } 

    cvtColor(img0, yuv, COLOR_BGR2YCrCb); 
    cvtColor(img0, gray, COLOR_BGR2GRAY); 
    cvtColor(gray, img, COLOR_GRAY2BGR); 
    img.copyTo(ellipses); 

    vector<vector<Point> > contours; 
    double t = (double)getTickCount(); 
    MSER()(yuv, contours); 
    t = (double)getTickCount() - t; 
    printf("MSER extracted %d contours in %g ms.\n", (int)contours.size(), 
      t*1000./getTickFrequency()); 

    // draw mser's with different colors 
    for(int i = (int)contours.size()-1; i >= 0; i--) 
    { 
     const vector<Point>& r = contours[i]; 
     for (int j = 0; j < (int)r.size(); j++) 
     { 
      Point pt = r[j]; 
      img.at<Vec3b>(pt) = bcolors[i%9]; 
     } 

     // find ellipse (it seems cvfitellipse2 have error or sth?) 
     RotatedRect box = fitEllipse(r); 

     box.angle=(float)CV_PI/2-box.angle; 
     ellipse(ellipses, box, Scalar(196,255,255), 2); 
    } 

    imshow("original", img0); 
    imshow("response", img); 
    imshow("ellipses", ellipses); 

    waitKey(0); 
} 

當我生成並運行此代碼,我得到下面的輸出之後,應用程序停止響應:

MSER extracted 1584 contours in 1748.41 ms. 
OpenCV Error: Assertion failed (points.checkVector(2) >= 0 && (points.depth() == 
CV_32F || points.depth() == CV_32S)) in unknown function, file 
..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 2019 

任何想法究竟是什麼問題?我完全失去了!

我試過註釋掉外部for循環中的所有內容,並且似乎問題在於RotatedRect和fitEllipse部分。我不完全確定雖然。任何幫助將不勝感激!

回答

1

您可以仔細檢查變量的數據類型。從錯誤消息中,某些函數只能使用Mat變量,其中任一個爲CV_32FCV_32S

0
  1. 將您的平臺工具集更改爲Visual Studio 2010。 (配置屬性 - >常規 - >平臺工具集)

  2. 確保您使用的二進制文件中opencv\build\x{86|64}\vc10

vc10的二進制文件,用VS 2010建成並與2012年VS不相容OpenVC沒有提供原生VS 2012版本。