Ask Your Question
0

Unknown compiler error?

asked 2018-07-26 08:17:51 -0500

Sencis gravatar image

When you build the project, you may receive strange error:

error 1 error LNK2019: reference to an unresolved external character cvUpdateMotionHistory in function "void __cdecl update_mhi(struct _IplImage *,struct _IplImage *,int)" (?update_mhi@@YAXPEAU_IplImage@@0H@Z)

error 2 error LNK2019: reference to an unresolved external character cvCalcMotionGradient in function "void __cdecl update_mhi(struct _IplImage *,struct _IplImage *,int)" (?update_mhi@@YAXPEAU_IplImage@@0H@Z)

//CV 3.3.0
#include "opencv\highgui.h"
#include <time.h>
#include <math.h>
#include <ctype.h>
#include <stdio.h>


using namespace cv;

static void help(void)
{
    printf(
        "\nThis program demonstrated the use of motion templates -- basically using the gradients\n"
        "of thresholded layers of decaying frame differencing. New movements are stamped on top with floating system\n"
        "time code and motions too old are thresholded away. This is the 'motion history file'. The program reads from the camera of your choice or from\n"
        "a file. Gradients of motion history are used to detect direction of motoin etc\n"
        "Usage :\n"
        "./motempl [camera number 0-n or file name, default is camera 0]\n"
        );
}


// various tracking parameters (in seconds)
const double MHI_DURATION = 1;
const double MAX_TIME_DELTA = 0.5;
const double MIN_TIME_DELTA = 0.05;
// number of cyclic frame buffer used for motion detection
// (should, probably, depend on FPS)
const int N = 4;

// ring image buffer
IplImage **buf = 0;
int last = 0;

// temporary images
IplImage *mhi = 0; // MHI
IplImage *orient = 0; // orientation
IplImage *mask = 0; // valid orientation mask
IplImage *segmask = 0; // motion segmentation map
CvMemStorage* storage = 0; // temporary storage

IplImage *mhi_1 = 0;
IplImage *dst_1 = 0;






// parameters:
//  img - input video frame
//  dst - resultant motion picture
//  args - optional parameters
static void  update_mhi(IplImage* img, IplImage* dst, int diff_threshold)
{
    double timestamp = (double)clock() / CLOCKS_PER_SEC; // get current time in seconds
    CvSize size = cvSize(img->width, img->height); // get current frame size
    int i, idx1 = last, idx2;
    IplImage* silh;
    CvSeq* seq;
    CvRect comp_rect;
    double count;
    double angle;
    CvPoint center;
    double magnitude;
    CvScalar color;

    // allocate images at the beginning or
    // reallocate them if the frame size is changed
    if (!mhi || mhi->width != size.width || mhi->height != size.height) {
        if (buf == 0) {
            buf = (IplImage**)malloc(N*sizeof(buf[0]));
            memset(buf, 0, N*sizeof(buf[0]));
        }

        for (i = 0; i < N; i++) {
            cvReleaseImage(&buf[i]);
            buf[i] = cvCreateImage(size, IPL_DEPTH_8U, 1);
            cvZero(buf[i]);
        }
        cvReleaseImage(&mhi);
        cvReleaseImage(&orient);
        cvReleaseImage(&segmask);
        cvReleaseImage(&mask);

        mhi = cvCreateImage(size, IPL_DEPTH_32F, 1);
        cvZero(mhi); // clear MHI at the beginning
        orient = cvCreateImage(size, IPL_DEPTH_32F, 1);
        segmask = cvCreateImage(size, IPL_DEPTH_32F, 1);
        mask = cvCreateImage(size, IPL_DEPTH_8U, 1);
    }

    cvCvtColor(img, buf[last], CV_BGR2GRAY); // convert frame to grayscale

    idx2 = (last + 1) % N; // index of (last - (N-1))th frame
    last = idx2;

    silh = buf[idx2];
    cvAbsDiff(buf[idx1], buf[idx2], silh); // get difference between frames

    cvThreshold(silh, silh, diff_threshold, 1, CV_THRESH_BINARY); // and threshold it
    cvUpdateMotionHistory(silh, mhi, timestamp, MHI_DURATION); // update MHI

    // convert MHI to blue 8u image
    cvCvtScale(mhi, mask, 255. / MHI_DURATION,
        (MHI_DURATION - timestamp)*255. / MHI_DURATION);
    cvZero(dst);
    cvMerge(mask, 0, 0, 0, dst);

    // calculate motion gradient orientation and valid orientation mask
    cvCalcMotionGradient(mhi, mask, orient, MAX_TIME_DELTA, MIN_TIME_DELTA, 3);

    if (!storage)
        storage = cvCreateMemStorage(0 ...
(more)
edit retag flag offensive close merge delete

Comments

which opencv version is it ?

(and you MUST NOT use that outdated c-apip code, deprecated since 2010)

berak gravatar imageberak ( 2018-07-26 08:28:05 -0500 )edit

the implementation for those functions were removed, thus the errors

berak gravatar imageberak ( 2018-07-26 08:35:29 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-07-26 08:33:45 -0500

berak gravatar image

updated 2018-07-26 08:34:37 -0500

with opencv3, the c-api motion history functions were moved to opencv_contrib and ported to proper c++.

but, this means:

  • you can no more use the code above
  • you have to rebuild your opencv libs with opencv_contrib .

  • if you want to stay with 3.3, make sure to checkout exactly the same branch there, else updating BOTH repos to current 3.4 would be best.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-07-26 08:17:51 -0500

Seen: 59 times

Last updated: Jul 26 '18