Ask Your Question

Nihad's profile - activity

2020-07-10 11:37:36 -0600 received badge  Famous Question (source)
2020-03-14 20:41:41 -0600 received badge  Popular Question (source)
2018-04-24 22:47:04 -0600 received badge  Notable Question (source)
2018-04-19 01:14:21 -0600 received badge  Notable Question (source)
2018-03-11 01:18:29 -0600 received badge  Notable Question (source)
2017-05-24 04:48:12 -0600 received badge  Popular Question (source)
2017-05-09 04:23:10 -0600 received badge  Popular Question (source)
2017-04-19 17:15:51 -0600 received badge  Notable Question (source)
2017-04-14 18:01:09 -0600 received badge  Nice Question (source)
2016-02-22 13:22:03 -0600 received badge  Popular Question (source)
2016-01-14 08:46:24 -0600 received badge  Famous Question (source)
2015-08-23 21:27:13 -0600 received badge  Popular Question (source)
2015-03-22 07:36:08 -0600 received badge  Notable Question (source)
2014-12-09 13:52:54 -0600 marked best answer Problem related to image pixel draw in .png format

I have 6 images with 256 by 256 dimension. I want to draw only first image with dimension 100 by 100. Here in my code segment. I tried in following way but failed to draw. How can i do this?

int main(..)
{
............................
 cv::Mat image[6] = cv::Mat::zeros(256, 256, CV_8U);

  for (int i = 0; i < 6; i++) {
    rasterizer.rasterize_depthbuffer(mesh, image[i], i, true);
    std::ostringstream stream;
    stream << i;
    std::string count = stream.str();
    cv::imwrite("image/test" + count + ".png", image[i]);
  }

   for (int y = 0; y < 100; y++) {
      for (int x = 0; x < 100; x++) {
       cv::imwrite("image/test.png", image[0].at<double>(y, x));
      }
    }

}
2014-12-09 13:52:51 -0600 marked best answer PCA calculation error.

I tried to calculate PCA, but I failed. Whats wrong with this approach? Here is error msg and code segment.

OpenCV Error:

 Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si
ze.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channel
s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3
) - 1))*4) & 15) == elemSize1()) in unknown function, file c:\program files (x86
)\opencv2.2\include\opencv2\core\mat.hpp, line 517
exception caught: c:\program files (x86)\opencv2.2\include\opencv2\core\mat.hpp:
517: error: (-215) dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (u
nsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) && ((((s
izeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) &
15) == elemSize1()

Code segement:

int main(..)
{
.......Read read_feature two dimensional array////////////////
number_of_lines=907;
feature_vector_size=300;
Mat input_feature_vector(number_of_lines,feature_vector_size,CV_32F);

    for(i=0;i<number_of_lines;i++)
    {
        for(j=0;j<feature_vector_size;j++)
        {
            input_feature_vector.at<float>(i,j)=read_feature[i][j];

        }

    }

    cout<<input_feature_vector<<endl;

    Mat projection_result;

    PCA pca(input_feature_vector,Mat(),CV_PCA_DATA_AS_ROW, 0); ///error msg

    /*cout<<"PCA Mean:"<<endl;
    cout<<pca.mean<<endl;*/

    pca.project(input_feature_vector,projection_result);

    //cout<<"PCA Projection Result:"<<endl;
    //cout<<projection_result<<endl;
}
2014-12-09 13:49:52 -0600 marked best answer How can I run OpenCV program?

I am trying to run an OpenCV program from command line, but it gave error like "The program can`t start because opencv_220d.dll is missing from your computer." Try reinstalling the program to fix this problem. I am using Windows 7 & Microsoft VC++ 2010. How can I run the program?

2014-12-09 13:49:43 -0600 marked best answer How can I reduce vector dimension using PCA?

I am trying to reduced vector size usig PCA. I am dealing with 907 objects(row), and each object has 300 feature vector(col.). I want to reduce feature vector size 50% which means resultant feature vector would be 150(col.) I use following code segment, but it retains all col. How can I reduce using PCA? Thnx in advance.

code:

int main(..)
{
.......Read read_feature two dimensional array////////////////
number_of_lines=907;
feature_vector_size=300;
Mat input_feature_vector(number_of_lines,feature_vector_size,CV_32F);

    for(i=0;i<number_of_lines;i++)
    {
        for(j=0;j<feature_vector_size;j++)
        {
            input_feature_vector.at<float>(i,j)=read_feature[i][j];

        }

    }

    cout<<input_feature_vector<<endl;

    Mat projection_result;

    PCA pca(input_feature_vector,Mat(),CV_PCA_DATA_AS_ROW, 0); 

    /*cout<<"PCA Mean:"<<endl;
    cout<<pca.mean<<endl;*/

    pca.project(input_feature_vector,projection_result);

    cout<<"PCA Projection Result:"<<endl;
    cout<<projection_result<<endl;
}
2014-12-09 13:49:22 -0600 marked best answer How can I create histogram from a set of values in OpenCV?

I have a text file which consist of several values. These values represent distance from origin to any point in the triangle. How can I create histogram from these values? Is there any functions in OpenCV which can create histogram from these values? Below my sample values are given:

..........................

3.4 1.2 6.9 0.2 5.1 2.9

.........................

2014-12-09 13:49:12 -0600 marked best answer How can I compare two histograms?

I am tying to compare two histograms, but it gives error. Here I have given my code, histogram file and error message. Histogram file 3*5 matrix(output_test.txt):

1 2 3 4 5
5 2 1 4 2
2 1 2 4 2

code:

int main(..........)
{
   ................................................
   Mat first_histogram(1,feature_vector_size, CV_32F);
   Mat second_histogram(1,feature_vector_size, CV_32F);

for(i=0;i<count_row;i++)
{
  for(j=0;j<count_row;j++) 
   {
    if(i==j)
    {
       comparision_feature[i][j]=0.0;
    }
    else
    {
       l=0;
    for(k=0;k<feature_vector_size;k++)
    {
        first_histogram.at <float>(l,k)=read_feature[i][k];
        second_histogram.at <float>(l,k)=read_feature[j][k];
    }
temp_distance=compareHist(first_histogram,second_histogram,CV_COMP_CORREL);//error message 
            comparision_feature[i][j]=temp_distance;
   }
    }
}

Error message: error LNK2019: unresolved external symbol "double __cdecl cv::compareHist(class cv::Mat const &,class cv::Mat const &,int)" (?compareHist@cv@@YANABVMat@1@0H@Z) Is there anybody who can help in this regard?

2014-12-09 13:48:22 -0600 marked best answer Output error dft() function

I am trying to use following code, but it gives error. Error message is like : OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si ze.p[0] && (unsigned)(i1DataType<_Tp>::channels) < (unsigned)(size.p[1]channel s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3 ) - 1))*4) & 15) == elemSize1()) in unknown function, file c:\program files (x86 )\opencv2.2\include\opencv2\core\mat.hpp, line 517

My code is given below:

int main(.....)
{
vector<double>pdf_vector;
//read data from file and put it in pdf_vector.
vector<double>all_vector;
Mat dft_input_vector(pdf_vector);
Mat dft_output_vector;
dft(dft_input_vector, dft_output_vector);

for(i=0;i<1;i++)
{
   for(j=0;j<pdf_vector.size ();j++)
    {
      all_vector.push_back (dft_output_vector.at <float>(i,j));
    }   
}

.................
}
2014-12-09 13:44:04 -0600 marked best answer Question about histogram output.

I have following code to create histogram, but it gave wrong output. In the program input_vector read 100 double numbers. I want to create a histogram with bin size=5. Output is [0;0;0;0;0]. Can anybody help me to figure out the problem?

vector<double>three_dimensional_shape_retreival_Hough_Transform:: histogram_creation(vector<double> input_vector)
{

    long int i;
    long int j;

    Mat histogram_input(input_vector);

    cout<<"Histogram Input Matrix:"<<histogram_input<<endl;

    int histSize =5;

    float max_distance= *max_element(input_vector.begin(), input_vector.end());
    float min_distance= *min_element(input_vector.begin(), input_vector.end());

    cout<<"Max Element:"<<max_distance<<" "<<"Min Element:"<<min_distance<<endl;

    float range[] = { min_distance,max_distance};
    const float* histRange = { range };

    bool uniform = true;
    bool accumulate = false;

    Mat histogram_output;

    calcHist(&histogram_input,1,0, Mat(), histogram_output,1,&histSize,&histRange,uniform,accumulate);

    cout<<"Histogram Output Matrix:"<<histogram_output<<endl;
}
2014-09-10 16:15:06 -0600 received badge  Popular Question (source)
2014-02-21 20:54:37 -0600 asked a question How can I multiply 3 matrices?

I would like to multiply 3 matrices(same size). For eample, NM=(-0.5)HSH where H,S are matrices having same size. Here is my code, but it produces nan output. How can i multiply 3 matrices?

int main()
{
.......................
int count_row=1000;
 vector <vector <float> >g;
//do some calculation on g

Mat M(count_row,count_row,CV_32F);
for(int i=0;i<count_row;i++)
{
     for(int j=0;j<count_row;j++)
     {
         M.at<float>(i,j)=g[i][j];

     }
}

Mat I = Mat::eye(count_row, count_row, CV_32F);

Mat H(count_row,count_row,CV_32F);
H=I-1.0/(float)count_row;

Mat S(count_row,count_row,CV_32F);
pow(M,2.0,S);

Mat normalized_M(count_row,count_row,CV_32F);
normalized_M=(-0.5)*H*S*H;

cout<<"normalized_M:"<<endl;
cout<<normalized_M<<endl;// error: produce nan output
}
2013-12-26 04:31:59 -0600 commented answer How can I initialize Mat with integer value?

Thank you!

2013-12-25 21:42:10 -0600 asked a question How can I initialize Mat with integer value?

I tried to initialize Mat with some int values, but it yielded error. How can I initialize Mat with some integer values? Here is my code:

int main(...)
{
Mat image(3, 3, CV_8U);

for(int y=0;y<3;y++)
{
  for(int x=0;x<3;x++)
  {
    image.at<int>(y,x)=0;//error here

  }
}
}
2013-12-17 23:04:06 -0600 answered a question Image difference

I change the code following way, but it gave only outer contour output. I think output should be inner contour because I subtract contour_image from canny_output.

int main (...)
{
Mat image = imread("test0.png",CV_LOAD_IMAGE_GRAYSCALE);
 Mat canny_output= Mat::zeros( image.size(), CV_8UC1);  
 vector<vector<cv::Point> > contours;
 vector<Vec4i> hierarchy;

 Canny(image, canny_output, 50, 200);

 findContours (image,  contours ,  hierarchy ,  cv :: RETR_EXTERNAL ,  cv :: CHAIN_APPROX_SIMPLE );

 Mat contour_image = Mat::zeros( image.size(), CV_8UC1);
for(int k= 0; k < contours.size(); k++)
{
    for(int l= 0; l < contours[k].size();l++)
    {
      contour_image.at<uchar>(contours[k][l])=255; 
    }
}
  Mat difference_image;
 absdiff( canny_output,contour_image, difference_image);

  imshow("Difference_image", difference_image); //Produce output same as contour_image
  cv::waitKey(0);
}
2013-12-16 01:38:34 -0600 asked a question Image difference

I tried to calculate difference between two images (Canny image and outer contour), but it gave black image. How can I show original difference between two images? Thanks in advance. Here is my code:

int main (...)
{
Mat image = imread("test0.png",CV_LOAD_IMAGE_GRAYSCALE);
 Mat canny_output;  
 vector<vector<cv::Point> > contours;
 vector<Vec4i> hierarchy;

 Canny(image, canny_output, 50, 200);

 findContours (image,  contours ,  hierarchy ,  cv :: RETR_EXTERNAL ,  cv :: CHAIN_APPROX_SIMPLE );

 Mat contour_image = Mat::zeros( image.size(), CV_8UC1);
for(int k= 0; k < contours.size(); k++)
{
    for(int l= 0; l < contours[k].size();l++)
    {
      contour_image.at<uchar>(contours[k][l])=255; 
    }
}
  Mat difference_image= Mat::zeros( image.size(), CV_8UC1);;
  difference_image=canny_output-contour_image;

  imshow("Difference_image", difference_image); //Produce black image
  cv::waitKey(0);
}
2013-12-05 05:46:31 -0600 commented answer How can I mark (white/255) in Mat for contour points?

Thanks works fine.

2013-12-05 05:36:06 -0600 commented answer How can I mark (white/255) in Mat for contour points?

Thanks it works. Novice question: in computer vision, we use contour_image.at<uchar><y,x> where y is row and x is col. So contours[k][l].x is row or col?

2013-12-05 05:22:13 -0600 asked a question How can I mark (white/255) in Mat for contour points?

I want to mark (white/255) in Mat for contour points. I tried following way, but get error. How can I do this? Thanks in advance.

int main(..)
{
 Mat image = imread("test0.png",CV_LOAD_IMAGE_GRAYSCALE);

vector<vector<cv::Point> > contours;
vector<Vec4i> hierarchy;

findContours (image,  contours ,  hierarchy ,  cv :: RETR_EXTERNAL ,  cv :: CHAIN_APPROX_SIMPLE );

Mat contour_image = Mat::zeros( image.size(), CV_8UC1);

for(int k= 0; k < contours.size(); k++)
{
   for(int l= 0; l < contours[k].size();l++)
   {
       int x1=contours[k][l].x;
       int y1=contours[k][l].y;
       contour_image.at<int>(y1,x1)=255;///error here
   }
}

  imshow("Contour_image", contour_image);
  cv::waitKey(0);

}
2013-11-27 02:55:31 -0600 commented answer How can I convert vector<Point2f> to vector<KeyPoint>?

Thank u. Is this possible to convert vector<Point2f> to vector<KeyPoint>? Neglecting the issue related to SIFT extractor. I have tried in following way, but failed. vector<KeyPoint>keypoints;

KeyPoint::convert(inputs,keypoints, 1, 1, 0, -1);

2013-11-27 02:22:46 -0600 asked a question How can I convert vector<Point2f> to vector<KeyPoint>?

I want to extract SIFT descriptor from my choosen points. How can I convert vector<point2f> to vector<keypoint>? Here is my code segment. Image resolution is 256 by 256. Thanks in advance.

int main(...)
{
.......................
Mat image = imread("test0.png",CV_LOAD_IMAGE_GRAYSCALE);
std::vector<cv::Point2f> inputs;

inputs.push_back(cv::Point2f(0,0));
inputs.push_back(cv::Point2f(0,30));
inputs.push_back(cv::Point2f(0,90));
inputs.push_back(cv::Point2f(0,120));

vector<KeyPoint> keypoints;

// Here how can I convert vector<cv::Point2f> inputs to vector<KeyPoint> keypoints?


  //Similarly, we create a smart pointer to the SIFT extractor.
  Ptr<DescriptorExtractor> featureExtractor = DescriptorExtractor::create("SIFT");

  // Compute the 128 dimension SIFT descriptor at each keypoint.
  // Each row in "descriptors" correspond to the SIFT descriptor for each keypoint
  Mat descriptors;
  featureExtractor->compute(image, keypoints, descriptors);
.........................
}
2013-11-26 04:44:11 -0600 commented question How can I see SIFT keypoints from an image?

Thanks. Now it works fine.

2013-11-26 03:57:54 -0600 asked a question How can I see SIFT keypoints from an image?

I tried to see SIFT keypoints from an image. I use following code, but I got some error msg given below: OpenCV Error: Assertion failed (scn == 1 && (dcn == 3 || dcn == 4)) in unknown f unction, file ........\ocv\opencv\modules\imgproc\src\color.cpp, line 2453

Here is my code:

#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <vector>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{        
  Mat image = imread("TestImage.jpg");

  // Create smart pointer for SIFT feature detector.
  Ptr<FeatureDetector> featureDetector = FeatureDetector::create("SIFT");
  vector<KeyPoint> keypoints;

  // Detect the keypoints
  featureDetector->detect(image, keypoints); // NOTE: featureDetector is a pointer hence the '->'.

  //Similarly, we create a smart pointer to the SIFT extractor.
  Ptr<DescriptorExtractor> featureExtractor = DescriptorExtractor::create("SIFT");

  // Compute the 128 dimension SIFT descriptor at each keypoint.
  // Each row in "descriptors" correspond to the SIFT descriptor for each keypoint
  Mat descriptors;
  featureExtractor->compute(image, keypoints, descriptors);

  // If you would like to draw the detected keypoint just to check
  Mat outputImage;
  Scalar keypointColor = Scalar(255, 0, 0);     // Blue keypoints.
  drawKeypoints(image, keypoints, outputImage, keypointColor, DrawMatchesFlags::DEFAULT);

  namedWindow("Output");
  imshow("Output", outputImage);



  return 0;

}

How can I see SIFT keypoints?

2013-06-08 22:16:18 -0600 asked a question Question about curvature estimation of a contour.

I am working with shape descriptor generation process. I can estimate contour from depth buffer image. Is this possible to estimate curvature of contour or bending energy of contour? I looked through the Opencv documentation and could not identify any reference. Your suggestion is most appreciable.

2013-06-05 05:31:15 -0600 commented question Problem related to access chain code value

Chain code is a kind of boundary descriptor. We can produce it from contour points. No problem if there is no function available. I need to develop code. Cheers!!

2013-06-04 19:35:05 -0600 commented question Problem related to access chain code value

@Guanta is there any function in current version which can represent contour as chain code?

2013-06-03 20:15:20 -0600 commented answer How can I normalize histogram?

Thank you.

2013-06-03 20:15:16 -0600 marked best answer How can I normalize histogram?

I want to normalize histogram between 0 and 1. Here is my code segment. It gave all zero output. Your help highly appreciable.

int main()
{
// .....................................
float histogram_sample[1][6]={2.0,2.0,3.0,4.0,1.0,2.0};

    Mat histogram(1,6,CV_32F,(void*)histogram_sample);

    cout<<"Histogram Matrix:"<<histogram<<endl;

    int histSize = 4;
    float start=1.0;
    float end=4.0;
    float range[] = { start,end+1.0 } ;
    const float* histRange = { range };

    bool uniform = true; bool accumulate = false;

    Mat hist;

    calcHist( &histogram, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform, accumulate );

    cout<<"hist:"<<hist<<endl;

    normalize(hist, hist, 0, 1, NORM_L2, -1, Mat());

    cout<<"Normalize hist:"<<hist<<endl;

}