Вопрос

I am using a Haar cascade classifier trained from the MIT cars dataset to detect vehicles in OpenCV (trained using the utilities provided with OpenCV). This works reasonably well when compiled in Debug mode, but when compiled in Release mode the cascade doesn't make any detections at all. Running the following code on the test image below gives a detection in debug mode but nothing in release mode (this behaviour continues through all images in my data sequence).

Can you suggest why this occurs and, more importantly, what I can do to obtain detections when running in Release mode?

Cascade File

Code

cv::Mat testImage = cv::imread("testImage.png",0);
cv::equalizeHist(testImage, testImage);

cv::CascadeClassifier vehicleCascade;
vehicleCascade.load("cars3.xml");

// Detect vehicles
std::vector<cv::Rect> cars;
vehicleCascade.detectMultiScale(
    testImage,                  // Input image
    cars,                   // Output bounding boxes
    1.1,                    // scale factor - how much image size is reduced at each scale
    5,                      // min neighbours - how many neighbours required to maintain rect
    0|CV_HAAR_SCALE_IMAGE,  // Not used
    cv::Size(30,30),        // Min poss object size
    cv::Size()              // Max poss object size
    );

std::cout << "Found " << cars.size() << " objects.\n";

for (int i=0; i<cars.size(); ++i)
    cv::rectangle(testImage, cars.at(i), CV_RGB(255,0,0), 3);

cv::namedWindow("Haar cascade");
cv::imshow("Haar cascade", testImage);
cv::waitKey(0);
cv::imwrite("output.png", testImage);

TestImage

testImage

Это было полезно?

Решение

  1. It's strange, but for me you code is working fine in both modes. I'm using Visual Studio 2010 on Windows 7 32bit. Here is my project - https://www.dropbox.com/s/5kubn5tlu7k6ziy/opencvhw.rar, so you can check executables(Release and Debug directories). If you are using visual studio and want to build it on your own you will have to change paths to library and include directories for both modes(include directories path is the same, library directories path is different). (project -> ... properties -> configuration properties -> vc++ directories)

  2. Generally i would recommend to check really carefully project configuration. It's really easy to make small mistake which can cause very weird behavior. Sometimes the best option is to configure everything from the scratch once again.

  3. OpenCV have very strange bugs - it's nothing new :) For example i can't use some codecs while debugging - if i run program in debug mode, but without debugging everything is fine, but if i try to debug - each frame readed from file is empty(but its size is correct). It's possible that you have just encountered something a bit similar. Try to convert image to different format(i think that bmp is the best choice for test - it's should always work without any additional libraries).

  4. Also note that you have uploaded jpg file so i had to rename and convert it on my own - maybe during conversions something in this file have changed so we are not testing your code on exactly the same files - upload you png file on dropbox so i can test it.

Другие советы

See this post: This type of error could be caused by linking to the debug library of opencv in release mode.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top