Ask Your Question

adarshmn's profile - activity

2014-08-12 04:38:56 -0600 commented question OpenCV Error: Image step is wrong () in cvSetData,

hay i tried but no output.

2014-08-12 00:35:09 -0600 commented question OpenCV Error: Image step is wrong () in cvSetData,

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

2014-08-11 07:14:23 -0600 asked a question 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 = 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;
}
2014-07-29 02:15:09 -0600 received badge  Editor (source)
2014-07-29 01:04:39 -0600 asked a question i have drawn the rectangle for mouth and i would like to crop that drawn position .how to do it?i am a beginner to openCV

here is my code for mouth detection.

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

int main(int argc, const char** argv) {
  VideoCapture cap(0);
  CascadeClassifier face, mouth;

  face.load("/home/adarsh/opencv/opencv-4.9/data/haarcascades/haarcascade_frontalface_default.xml");

  mouth.load("/home/adarsh/opencv/opencv-2.4.9/data/haarcascades/haarcascade_mcs_mouth.xml");

  Mat frame, grayframe, testframe;

  while (1) {
    cap.read(frame);

    if (!cap.read(frame)) 
    {
      printf("an error while taking the frame from cap");
    }

    vector<Rect> faces; 
    cvtColor(frame, grayframe, CV_BGR2GRAY);
    equalizeHist(grayframe, testframe);
    face.detectMultiScale(testframe, faces, 1.1, 3, CV_HAAR_SCALE_IMAGE,
                          Size(30, 30));

    for (int i = 0; i < faces.size(); i++)
    {
      rectangle(frame, faces[i], Scalar(255, 0, 0), 1, 8, 0);
      Mat face = frame(faces[i]);
      cvtColor(face, face, CV_BGR2GRAY);
      vector<Rect> mouthi;
      mouth.detectMultiScale(face, mouthi);

      for (int k = 0; k < mouthi.size(); k++) 
      {
        Point pt1(mouthi[0].x + faces[i].x, mouthi[0].y + faces[i].y);
        Point pt2(pt1.x + mouthi[0].width, pt1.y + mouthi[0].height);
        rectangle(frame, pt1, pt2, Scalar(255, 0, 0), 1, 8, 0);
      }
    }

    imshow("output", frame);

    int c = waitKey(10);
    if ((char) c == 27){
      break;
    }
  }
  return 0;
}