opencv LoadModel() read access violation

asked 2018-10-11 06:22:54 -0600

XCENAX gravatar image

updated 2018-10-11 06:26:41 -0600

berak gravatar image

Hi, I try to load trained model "lbfmodel.yaml" by loadModel(). Сompilator gives read access error. "lbfmodel.yaml" located in project root folder

Here is a code:

#include <windows.h>

#include "opencv.hpp"
#include "face/include/opencv2/face.hpp"
#include "drawLandmarks.hpp"
#include "facemark.hpp"
#include "facemarkLBF.hpp"
#include <kernelspecs.h>
using namespace cv;
using namespace cv::face;

#include <iostream>
using namespace std;





int main(int argc, char** argv)
{

    LoadLibrary("opencv_highgui400d.dll");
    LoadLibrary("opencv_core400d.dll");
    LoadLibrary("opencv_videoio400d.dll");
    LoadLibrary("opencv_imgproc400d.dll");
    LoadLibrary("opencv_objdetect400d.dll");

    cv::CascadeClassifier faceDetector("haarcascade_frontalface_alt2.xml");

    Ptr<Facemark> facemark = FacemarkLBF::create();

    facemark->loadModel("lbfmodel.yaml");

    VideoCapture cam(0);

    Mat frame, gray;

    while (cam.read(frame))
    {
        vector<Rect> faces;

        cvtColor(frame, gray, COLOR_BGR2GRAY);

        faceDetector.detectMultiScale(gray, faces);

        vector< vector<Point2f> > landmarks;

        bool success = facemark->fit(frame, faces, landmarks);

        if (success)
        {
            for (int i = 0; i < landmarks.size(); i++)
            {
                drawLandmarks(frame, landmarks[i]);
            }
        }

        imshow("Facial Landmark Detection", frame);
        if (waitKey(1) == 27) break;
    }
    return 0;
}
edit retag flag offensive close merge delete

Comments

what are those LoadLibrary calls doing there ?

(that's not the right way to do it, and they have no effect at all)

#include <kernelspecs.h> ?? #include <windows.h> nooo, throw it all out.

Сompilator gives read access error.

be more precise here. there are 3 steps: compilation, linking and running the program. the lbf model isonly relevant in the last step.

also: we need the exact error msg here !

berak gravatar imageberak ( 2018-10-11 06:31:16 -0600 )edit

actually, ALL your includes look broken ! all you should need is:

#include "opencv2/opencv.hpp"
#include "opencv2/face/facemark.hpp"
#include "drawLandmarks.hpp" // assuming, that's the one from satyia's site !
berak gravatar imageberak ( 2018-10-11 06:36:14 -0600 )edit

here's error An exception was thrown at the address 0x00007FF74E1A50CF in Opencv.exe: 0xC0000005: read access violation at 0x0000000000000000.

XCENAX gravatar imageXCENAX ( 2018-10-11 06:41:06 -0600 )edit

again, the 1st thing you should do is clean up the code, use proper includes & libs.

berak gravatar imageberak ( 2018-10-11 06:42:53 -0600 )edit

are you sure, your model is correct ? (it should be about 50mb for the prebuilt one)

berak gravatar imageberak ( 2018-10-11 06:44:12 -0600 )edit

"lbfmodel.yaml" located in project root folder.

ok, but are you starting your program from there ? (run it from a cmdline, NOT from your ide)

berak gravatar imageberak ( 2018-10-11 06:45:59 -0600 )edit

I also want to ask: how to properly connect dll files to the project because when i try to look at the information on faceDetector the compiler writes that "Information not available, symbols for opencv_objdetect400d.dll not loaded"

XCENAX gravatar imageXCENAX ( 2018-10-11 06:48:39 -0600 )edit
1
XCENAX gravatar imageXCENAX ( 2018-10-11 06:49:21 -0600 )edit

"Information not available, symbols for opencv_objdetect400d.dll not loaded"

that means, you misconfigured your VS project, and it can't find the corresponding .pdb files

(it's NOT about the dll's !)

again, already the way you setup the includes looks wrong, all your problems might be related, to how you use VS.

berak gravatar imageberak ( 2018-10-11 06:58:55 -0600 )edit

don't you know where pdb files should be?

XCENAX gravatar imageXCENAX ( 2018-10-11 07:02:10 -0600 )edit