0

I am working with visual-studio and opencv lib and I have been trying to use findContours() but no matter what parameters I give the function it always triggers a break-point,

I have tried to make the image binary (b&w), reinstalling the library in different versions, messing with the linker preferences and anything I'v found on the web.

(this code is one of many i found on the web - they all crush one they get to findContours)

Does anyone know how to solve this problem ?

#include <iostream>
#include <vector>
#include "opencv2/opencv.hpp"

using namespace cv;
using std::vector;

int main()
{
    vector<vector<cv::Point>> contours = vector<vector<cv::Point>>();
    vector<Vec4i> hierarchy;
    Mat frame, cont, threshold_;

    VideoCapture capture = VideoCapture(0);

    if (!capture.isOpened())
    {
        return -1;
    }

    while (true)
    {
        capture >> frame;
        if (frame.empty()) break;

        cont = frame.clone();
        cvtColor(cont, cont, COLOR_BGR2GRAY);

        cv::threshold(cont, cont, 128, 255, THRESH_BINARY);
        threshold_ = cont.clone();

        findContours(cont, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);

        for (unsigned int i = 0; i < contours.size(); i++) 
        {
            drawContours(frame, contours, i, Scalar(0, 0, 255), 2);
        }

        imshow("Contour", threshold_);
        imshow("Video", frame);

        if (cv::waitKey(30) == 'q')
        {
            break;
        }
    }
    return 0;
}
May
  • 1
  • 3
  • well, this example is quite poorly coded, but will work as expected as soon as you correct the line to `if (cv::waitKey(30) == 'q')` (note the parenthesis). Do you have problems also finding contours on images, or on video from your webcam only? If so, check if your webcam delivers rgb or gray images. (If the problem is that it triggers a breakpoint, just remove the breakpoint. If it crashes, it's another story...) – Miki Jul 30 '15 at 22:24
  • didn't notice the waitKey problem, anyway it's not it... there's no break point - it just triggers one (?) i have no idea how – May Jul 30 '15 at 22:35
  • well ok.. not important now.. what about the rest of my comment? – Miki Jul 30 '15 at 22:36
  • just tried to use a Image and i cause the same problem.... anyway I print the image before and after i change it to COLOR_BGR2GRAY and it looks pretty fine... – May Jul 30 '15 at 22:45
  • check your dll, you're probably mixing debug and release dll (or libs) – Miki Jul 30 '15 at 22:48
  • i have tried kindof everything i could think of in the project properties, reinstalled the library like 3 times in different visions (also deleted after every time of course) and nothing seemed helped.... do u maybe have a more specific answer ? :\ (sorry that I'm rude, it's just cause I am really desperate at this point...) – May Jul 30 '15 at 22:59
  • list the libs you're using – Miki Jul 30 '15 at 23:01
  • opencv_ts300.lib opencv_world300.lib -on debug – May Jul 30 '15 at 23:01
  • try opencv_ts300d.lib opencv_world300d.lib – Miki Jul 30 '15 at 23:02
  • tried it already it shouts over MSVCP110D.dll missing nothing works with those... (with the other ones it's all working apart of- findContours() function. – May Jul 30 '15 at 23:06
  • what visual studio are you using? and with which compiler is compiled the opencv you're using? (you should use *d.lib if you're in DEBUG, no matter what) – Miki Jul 30 '15 at 23:10
  • I am using visual studio 2015 RC don't know which compiler was used - I downloaded it from their site (it's version 3.0) – May Jul 30 '15 at 23:17
  • what's your library directory for opencv libs? I think is something like OPENCV_DIR/build/x86 (or x64) /vc12 – Miki Jul 30 '15 at 23:19
  • C:\opencv\build\x86\vc11\lib – May Jul 30 '15 at 23:21
  • ok.. that's the problem... you are using opencv compiled with msvc11, while you're using a different runtime... – Miki Jul 30 '15 at 23:21
  • go to Properties -> General -> Platform Toolset and set VisualStudio 2012(v110). Or link to directory C:\opencv\build\x86\vc12\lib and set VisualStudio 2013(v120) – Miki Jul 30 '15 at 23:23
  • I'm going soon.. any luck with that? OpenCV is not prebuilt for VS2015. You should do one of: 1) change the platform toolset of VS2015 to fit a precompiled version of OpenCV (VS2012 and VS2013), 2) use VS2012 or VS2013 instead of VS2015, 3) compile OpenCV for VS2015. – Miki Jul 30 '15 at 23:40
  • just tried that : C:\opencv\build\x86\vc12\lib and set VisualStudio 2013(v120) but it couse the same – May Jul 31 '15 at 11:13
  • You're probably messing up too many stuff. I'm installing VS2015 to see how make it work and then come back to you. My recommendation, however, is to install VS2013 – Miki Jul 31 '15 at 11:19
  • haha yea that was what i have done.... edit: it can't find opencv_world300d.lib – May Jul 31 '15 at 11:20
  • Have you linked to C:\opencv\build\x86\vc12\lib and are you sure your project is 32 bit? – Miki Jul 31 '15 at 11:26
  • Well, as I said, you probably have a few settings messed up. Try following [these](http://stackoverflow.com/a/31545237/5008845) steps. It will work! – Miki Jul 31 '15 at 11:36
  • I have no idea how but it works now! tank u so match! – May Jul 31 '15 at 11:41

0 Answers0