Ask Your Question

Mohammad Etemaddar's profile - activity

2015-01-26 22:48:33 -0600 commented question vector, copy and add to

You are right, I repaired the code. and it's now corrected by clone() method.

2015-01-26 00:51:24 -0600 answered a question Is there a direct way to print a Mat on one line ?

Maybe you need OpenCV print formats:

http://docs.opencv.org/doc/tutorials/...

2015-01-26 00:24:38 -0600 asked a question vector, copy and add to

When I create a vector and add new calculated Mat to it using for loop, it will add the same reference as my Mat has same name.

for example:

vector<Mat> hists;
for (int row = 0 ; row < 2 ; row++)
 for (int col = 0 ; col < 4 ; col++)
 {
  hist_mat.set_roi(row , col);
  hist_mat.run();
  hists.push_back(hist_mat.hist_h);
  cout << hist_mat.hist_h << endl;
 }

for (int i = 0 ; i < 8 ; i++)
{
  cout << hists[i] << endl;
}

although the first cout has different lines, The second "cout" will have same lines (The last added element); Because all vector elements has same reference. What is a good way to copy and add to the vector?

2015-01-09 04:00:39 -0600 commented question Tool for cropping positive samples

Your English is good, But would you mind give an example of pictures, and your need in output?

2015-01-09 03:57:30 -0600 received badge  Autobiographer
2015-01-08 14:18:50 -0600 received badge  Nice Answer (source)
2015-01-08 08:32:16 -0600 received badge  Teacher (source)
2015-01-08 07:19:11 -0600 received badge  Editor (source)
2015-01-08 07:18:26 -0600 answered a question best development platform

If you do not want IDE to run, You can use gcc, cmake and make. It is explained in documentation. I use this method. Works fine. I like it, Because it's simpler to understand than other ways for me. You can use any editor you like. I use both vim and sublime on Linux.

Of course as you may know, OpenCV serves python, Java, C# and other. If you use python, then you do not need compiler, Just python and editor :) If you use IDE, It would be more pleasant and more easy to code.

2015-01-08 07:11:52 -0600 commented question Extract each label after Connected Component Labeling

It would be appreciated if you explain your code a little. Thanks.

2015-01-08 07:09:24 -0600 received badge  Supporter (source)
2015-01-08 07:06:53 -0600 asked a question Calculate Histogram of Hue

I want to compare my object by objects in database. So I decided to calculate their histogram of Hue and then compare my new Histogram by previous pictures. I decided to calculate Hue's histogram, Because I thought that it has low dependency to light.

This is my code: I have split the HSV picture and then I think that the first element of vector will have the Hue value. But it is surprising that I get the second line of output for every picture on 1080.

First I want to know if this code has written true for the purpose and then It would be appreciated if you help me by improving my code in both algorithm and programming manner.

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;

class mycalchist
{
public:
    Mat src_hsv, src_h, hist_h;
    mycalchist(Mat);
    void setHistSize(int);
    void run();
    int histSize;

private:
    float range[2];
    const float* histRange;
    bool uniform; bool accumulate;
    vector<Mat> src_hsv_vector;
};

int main(int argc, char** argv)
{
    Mat src;
    if (argc > 1)
    {

        src = imread(argv[1]);
        if (!src.data)
        {
            return -1;
        }
    }
    else
        cout << "Usage: " << argv[0] << " <image file name>" << endl;


    mycalchist image(src);
    image.run();

    for (int i=0;i<image.histSize; i++)
        cout << image.hist_h.at<float>(0,i) << endl;
    imshow("src",src);
    waitKey(0);
    return 0;

}

mycalchist::mycalchist(Mat src)
{
    cvtColor(src,this->src_hsv,CV_RGB2HSV);
    split (this->src_hsv,src_hsv_vector);
    this->src_h = src_hsv_vector[0];
    this->range[0] = 0;
    this->range[1] = 256;
    this->histRange = {this->range};
    this->uniform = true;
    this->accumulate = false;
    this->histSize = 10;
}

void mycalchist::run()
{
    calcHist( &this->src_h, 1, 0, Mat(), this->hist_h, 1, &this->histSize, &this->histRange, this->uniform, this->accumulate );
    normalize(this->hist_h, this->hist_h, 0, this->src_h.rows, NORM_MINMAX, -1, Mat() );
}

output:

55.3835
1080
196.67
12.1901
3.30496
0.169019
0.27043
0
0
0