Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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 = 4; 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;

}

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

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 = 4; 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;

}

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

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. 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'

'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>

*/ #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> using namespace std; using namespace cv;

/* cv; /** * @function main */ int main(int argc, char* 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;
}

}