Ask Your Question
0

Problem with cvCompareHist

asked 2013-04-01 13:25:56 -0600

updated 2020-10-05 08:03:19 -0600

Hi I'm trying to use cvCompareHist to detect an object entering the frame all the methods seem to be returning a value except for cvCompareHist the code builds succesfully with no errors and crashes at runtime when I quick watch the cvCompreHist method I get an error "CX0017: Error:symbol "cvCompareHist" not found". Here's the code till that point

#include "opencv\cv.h"
#include"opencv2\core\core.hpp" // Basic OpenCV structures (cv::Mat, Scalar)
#include "opencv\highgui.h" // OpenCV window I/O
#include "opencv2\imgproc\imgproc.hpp"

#include <iostream> // for standard I/O
#include <string>   // for strings
#include <iomanip>  // for controlling float print precision
#include <sstream>  // string to number conversion
#include <stdio.h>
    void ImagesAreDifferent(IplImage* frame, IplImage* previousFrame);

    using namespace std;
    using namespace cv;

    int main(int argc, char** argv)
    {
        cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE ); //creates window
        //CvCapture* capture = cvCreateCameraCapture( -1); //to select camera
        CvCapture* capture = cvCreateFileCapture("test video.mp4"); //uses test video
        IplImage* frame; //holds one frame from the video/camera
        IplImage* referenceFrame = NULL; //will hold the reference frame
        IplImage* currentFrame = NULL;
        IplImage* h_plane = NULL;
        IplImage* s_plane = NULL;
        IplImage* v_plane = NULL;
        IplImage* h_planeC = NULL;
        IplImage* s_planeC = NULL;
        IplImage* v_planeC= NULL;
        IplImage* previousFrame = NULL; //this is used to determine if the object is moving




        /// Using 30 bins for hue and 32 for saturation
        int h_bins = 30; int s_bins = 32;
        // Build and fill the histogram
        CvHistogram* frameA;
        {
            int hist_size[] = { h_bins, s_bins };
            float h_ranges[] = { 0, 255 };
            float s_ranges[] = { 0, 180 };
            float* ranges[] = { h_ranges, s_ranges };
            frameA = cvCreateHist( 2, hist_size, CV_HIST_ARRAY, ranges, 1 );
        }

        CvHistogram* frameB;
        {
            int hist_size[] = { h_bins, s_bins };
            float h_ranges[] = { 0, 255 };
            float s_ranges[] = { 0, 180 };
            float* ranges[] = { h_ranges, s_ranges };
            frameB = cvCreateHist( 2, hist_size, CV_HIST_ARRAY, ranges, 1 );
        }

        bool firstFrame = true;

        while(1) //run indefinitely
        {
            frame = cvQueryFrame( capture ); //takes the next frame 

            //sets the reference frame
            if(firstFrame)
            {
                //these are the three layers from the color scheme we are converting to
                //the change in color scheme is for better comparison
                h_plane = cvCreateImage( cvGetSize(frame), 8, 1);
                s_plane = cvCreateImage( cvGetSize(frame), 8, 1);
                v_plane = cvCreateImage( cvGetSize(frame), 8, 1);
                referenceFrame = cvCreateImage(cvGetSize(frame), 8,3); //set the reference frame
                cvCvtColor(frame, referenceFrame, CV_BGR2HSV);         //change the color scheme
                IplImage* referenceFrameArray[] = {h_plane, s_plane};  //put the h and s layers into an array for creation of the histogram
                cvCvtPixToPlane( referenceFrame, h_plane, s_plane, v_plane, 0); //break the image into the three layers
                cvCalcHist(referenceFrameArray, frameA, 0, 0);         //calculate the histogram value
                cvNormalizeHist( frameA, 1.0);                         //normalize the histogram
                firstFrame = false;
            }
            else
            {
                //these are the three layers from the color scheme we are converting to for current frame
                h_planeC = cvCreateImage( cvGetSize(frame), 8, 1);
                s_planeC = cvCreateImage( cvGetSize(frame), 8, 1);
                v_planeC = cvCreateImage( cvGetSize(frame), 8, 1);
                //get histograms for fast simple comparison of frames
                currentFrame = cvCreateImage(cvGetSize(frame), 8,3);   //set the current frame
                cvCvtColor(frame, currentFrame, CV_BGR2HSV);           //change the color scheme
                IplImage* currentFrameArray[] = {h_planeC, s_planeC};    //put the h and s layer into an array for creation of the histogram
                cvCvtPixToPlane( currentFrame, h_planeC, s_planeC, v_planeC, 0); //break apart the image into the three layers
                cvCalcHist(currentFrameArray, frameB, 0, 0 ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-04-01 13:55:07 -0600

Can you check if you actually added the opencv library path to your systems path variable.

And also check if you included all necessary libraries in linker settings of your project.

These are two most common reasons for missing functions.

edit flag offensive delete link more

Comments

Every other openCV method we are using works correctly. This is the only one that is giving us any kind of problem and it isn't throwing any error.

mrcclassical gravatar imagemrcclassical ( 2013-04-05 13:31:05 -0600 )edit

In VisualStudio I am able to right click on the method and "go to definition" which should mean that the method is recognized correctly.

mrcclassical gravatar imagemrcclassical ( 2013-04-05 13:33:22 -0600 )edit

Okay that means he knows the linker folder at running time. Check if all your libraries are with the d in the name for debug mode. I have looked around and this seems to be a frequent error in the lib names. Forgetting a single d can lead to this problem, expecially if this is the only function you are using from that specific library.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-05 13:53:26 -0600 )edit

Question Tools

Stats

Asked: 2013-04-01 13:25:56 -0600

Seen: 1,295 times

Last updated: Apr 01 '13