Ask Your Question

mrcclassical's profile - activity

2013-04-05 13:37:33 -0600 commented question cvCompareHist error

I am running in Visual Studio so I can place break points, highlight the function, and say add to quick watch. By doing this I can find out what a method will output while having the code execution paused. I hope that is clearer.

2013-04-05 13:33:22 -0600 commented answer Problem with cvCompareHist

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

2013-04-05 13:31:05 -0600 commented answer Problem with cvCompareHist

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.

2013-04-01 13:25:56 -0600 asked a question Problem with cvCompareHist

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)
2013-03-29 15:04:38 -0600 asked a question cvCompareHist error

I am trying to use cvCompareHist to monitor a video feed and alert the user when something enters the frame and stays there, but I am getting an error at run-time that states that cvCompareHist cannot be found. Any ideas why this is? There is no error prior to running the code so the method seems to be available prior to running the code.

2013-03-13 14:42:59 -0600 asked a question Problem with cvCalcHist

I am trying to detect when an object enters a video feed using histograms and comparisons, but cvCalcHist is giving me an error: "Unhandled exception at 0x774515de in opencv test.exe: 0xC0000005: Access violation reading location 0xcccccccc."

any help at all would be appreciated.

Thanks

#include "opencv\cv.h"
#include "opencv\highgui.h" //include it to use GUI functions.
#include "opencv2\imgproc\imgproc.hpp"
#include <iostream>
#include <stdio.h>

void ImagesAreDifferent(IplImage* frame, IplImage* previousFrame);

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* previousFrame = NULL; //this is used to determine if the object is moving 
    IplImage* currentFrameArray[1];
    IplImage* referenceFrameArray[1];

    /// Using 30 bins for hue and 32 for saturation
    int h_bins = 30; int s_bins = 32;
    int histSize[] = { h_bins, s_bins };

    // 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)
        {
            referenceFrame = frame;
            cvCvtColor(frame, referenceFrame, CV_BGR2HSV);          
            referenceFrameArray[0] = referenceFrame;
            firstFrame = false;
        }

        //get histograms for fast simple comparison of frames
        currentFrameArray[0] = frame;
        cvCvtColor(frame, currentFrameArray[0], CV_BGR2HSV);
        cvCalcHist(currentFrameArray, frameA);
        cvCalcHist(referenceFrameArray, frameB);
        //1.0 is a perfect match, 0.5 is a half match, -1 is complete mismatch
        if(cvCompareHist(frameA, frameB, CV_COMP_CORREL) < 0.8) 
        {
            //ImagesAreDifferent(frame, previousFrame);
        }

        if( !frame ) break; //if this is the end of the video then close
        cvShowImage( "Example2" , frame); //show the frame in the window

        char c = cvWaitKey(33); //get key pressed
        if( c == 27 ) break; // if key pressed is Esc then close
    }
    cvReleaseCapture( &capture ); //release video/camera
    cvDestroyWindow( "Example2" ); //close window
}