信息不可用,没有为opencv_world331d.lib加载符号

时间:2017-11-07 18:21:04

标签: c++ opencv dll

所以,基本上一切都适合我的程序。 该程序只是一个简单的背景估计,它使用BackgroundSubtractor类提取前景。但是,每当程序终止时,我都会遇到异常。我尝试调试它,错误消息显示“信息不可用,没有为opencv_world331d.lib加载符号”

我该怎么做才能解决这个问题?

以下是代码:

/*This code detects people and draws a bounding box around them*/
/*Uses "background subtraction" in order to keep track of the moving objects in the frames*/
#include "cv.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
    Ptr<BackgroundSubtractor> bg_model = createBackgroundSubtractorMOG2();
    VideoCapture cap("people.mp4");
    Mat first_frame, frame, main_frame, avg, foregdMask, backgdImg, foregdImg, bg_subtraction, bg_gray;
    int cnt = 2;
    int cap_width = (int)cap.get(CV_CAP_PROP_FRAME_WIDTH);
    int cap_height = (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT);

    Mat kernel = getStructuringElement(MORPH_RECT, Size(5, 5));//Size(5,5)

    vector<vector<Point>>contours;
    vector<Vec4i>hierarchy;
    int w_threshold = 40; //contour thresholds
    int h_threshold = 60;
    int num_con;

    int fps = (int)(cap.get(CV_CAP_PROP_FPS));
    int delay = 1000 / fps;
    int frameNum = 0;

    bool stop = false;
    int key = 0;

    //Store the first frame(since it does not have any moving object present)
    cap >> first_frame;
    //imshow("FIRST_FRAME", first_frame);

    while (1) //For each loop, read single frame
    {
        if (!stop) {
            if (!cap.read(main_frame)) //Reads in the frame
                break;
            if (main_frame.empty())
            {
                cout << "Error! No frame received!" << endl;
                break;
            }

            frame = main_frame.clone();//Maintain a copy of the main frame

            cvtColor(main_frame, main_frame, CV_BGR2GRAY);

            medianBlur(main_frame, main_frame, 7);

            //Gaussian Mixture Model (GMM)
            if (foregdMask.empty()) //Our foreground mask
                foregdMask.create(frame.size(), frame.type());

            bg_model->apply(main_frame, foregdMask, true ? -1 : 0); //Compute foreground mask

            //GaussianBlur(foregdMask, foregdMask, Size(11, 11), 3.5, 3.5);
            GaussianBlur(foregdMask, foregdMask, Size(3, 3), 0.5, 0.5);

            threshold(foregdMask, foregdMask, 130, 255, THRESH_BINARY);

            foregdImg = Scalar::all(0);

            frame.copyTo(foregdImg, foregdMask);

            bg_model->getBackgroundImage(backgdImg);

            //erode(foregdMask, foregdMask, kernel, Point(-1, -1), 1);
            dilate(foregdMask, foregdMask, kernel, Point(-1, -1), 2);
            imshow("foreground Mask", foregdMask);
            imshow("foreground Image", foregdImg);
            imshow("gray frame", main_frame);

            //Finding contours(lines)
            findContours(foregdMask, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
            vector<Rect> rect(contours.size());

            num_con = 0;
            //Drawing rectangles around the contours
            for (int i = 0; i < contours.size(); i++)
                rect[i] = boundingRect(Mat(contours[i])); //Calculating the up-right bounding rectangle of point sets
            for (int i = 0; i < contours.size(); i++) {
                if (rect[i].width > w_threshold || rect[i].height > h_threshold)//The size of the contour must be larger than the thresholds
                {
                    rectangle(frame, rect[i], 0, 2, 8, 0); //Draw the boxes on the original frame
                    num_con++; //Count the number of boxes
                }
            }

            string c = to_string(num_con);

            putText(frame, "Number of people:", Point(200, 200), 1, 2, Scalar(0, 200, 0), 3, 8, false);
            putText(frame, c, Point(520, 200), 1, 2, Scalar(255, 200, 0), 3, 8, false);

            imshow("FRAME", frame);

            frameNum++; //Increment the number of frame per loop

            key = waitKey(delay);
            if (key == 32) //Pause
            {
                if (stop == false) 
                {
                    stop = true;
                }
                else
                    stop = false;
            }
            else if (key == 27) //"ESC" terminates the video
                break;
        }
        else //Resume
        { 
            key = waitKey(delay);
            if (key == 32)
                stop = false;
        }
    }
    return 0;
}

0 个答案:

没有答案