Ask Your Question
0

OpenCV Error: Image step is wrong () in cvSetData,

asked 2014-08-11 07:14:23 -0600

adarshmn gravatar image

updated 2014-08-12 05:11:14 -0600

hay i am new to opencv while i am reading sequence of images and copying it into array i can able to copy first image but for the further its giving exception.please help me out.

here is the exception i am getting.

OpenCV Error: Image step is wrong () in cvSetData, file /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/array.cpp, line 928
terminate called after throwing an instance of 'cv::Exception'

here is my program.i have 4 images in my images folder.here i am trying to calculate the histogram.

/**
 * @file compareHist_Demo.cpp
 * @brief Sample code to use the function compareHist
 * @author OpenCV team
 */

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

/**
 * @function main
 */
int main(int argc, char** argv) {

    Mat src_base[4];
    Mat hsv_base[4];
    double base_base[4];
    MatND hist_base[4];
    Mat image;
    /// Load three images with different environment settings
/*  if (argc < 4) {
        printf(
                "** Error. Usage: ./compareHist_Demo <image_settings0> <image_setting1> <image_settings2>\n");
        return -1;
    }
    */
    VideoCapture sequence("/home/adarsh/MOUTH/mouth_%d.jpg");
        if (!sequence.isOpened()) {
            cerr << "Failed to open Image Sequence!\n" << endl;
            return 1;
        }

    for (int i = 0; i < 4; i++) {
        sequence >> image;
        //src_base[i] = imread(argv[i], 1);
        src_base[i]=image;
        cvtColor( src_base[i], hsv_base[i], COLOR_BGR2HSV );
    }

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

    // hue varies from 0 to 179, saturation from 0 to 255
    float h_ranges[] = { 0, 180 };
    float s_ranges[] = { 0, 256 };

    const float* ranges[] = { h_ranges, s_ranges };

    // Use the o-th and 1-st channels
    int channels[] = { 0, 1 };

    /// Histograms


    for (int j = 0; j < 4; j++) {
        calcHist(&hsv_base[j], 1, channels, Mat(), hist_base[j], 2, histSize,
                ranges, true, false);
        normalize(hist_base[j], hist_base[j], 0, 1, NORM_MINMAX, -1, Mat());
    }

    /// Apply the histogram comparison methods
    for (int k = 0; k < 1; k++) {
        int compare_method = k;
        base_base[0] = compareHist(hist_base[0], hist_base[0], compare_method);
        base_base[1] = compareHist(hist_base[0], hist_base[1], compare_method);
        base_base[2] = compareHist(hist_base[0], hist_base[2], compare_method);
        base_base[3] = compareHist(hist_base[0], hist_base[3], compare_method);
        printf("The values are\n Method [%d] Perfect, Base-Test(1), Base-Test(2), Base-Test(3), : %f, %f, %f, %f\n",
                    k,base_base[0], base_base[1], base_base[2], base_base[3]);

    }


    printf("Done \n");

    return 0;
}
edit retag flag offensive close merge delete

Comments

hay sorry it was a mistake. nw i have updated the for loop.please look over it and rectify the issue.

adarshmn gravatar imageadarshmn ( 2014-08-12 00:35:09 -0600 )edit
1

sequence >> image;

if ( image.empty() ) {cerr << "arrrr empty!" << endl}

berak gravatar imageberak ( 2014-08-12 00:37:20 -0600 )edit

hay i tried but no output.

adarshmn gravatar imageadarshmn ( 2014-08-12 04:38:56 -0600 )edit

Look at the docs. You are using the parameter wrongly. It should be VideoCapture sequence("/home/adarsh/MOUTH/mouth_%02d.jpg");

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-12 06:09:05 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-08-12 05:38:31 -0600

You should allocate hsv_base images before using the cvtColor function. Also, don't use src_base in your loop, but directly image (or do a deep copy with the clone method) otherwise, you probably don't have what you expected in src_base.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-08-11 07:14:23 -0600

Seen: 1,646 times

Last updated: Aug 12 '14