Ask Your Question

abir's profile - activity

2018-03-12 20:13:16 -0500 received badge  Popular Question (source)
2017-07-17 23:39:14 -0500 received badge  Famous Question (source)
2017-02-08 09:15:29 -0500 received badge  Famous Question (source)
2016-10-25 08:12:08 -0500 received badge  Famous Question (source)
2016-02-19 01:13:07 -0500 received badge  Notable Question (source)
2016-02-11 03:07:50 -0500 received badge  Notable Question (source)
2016-01-27 03:48:51 -0500 received badge  Famous Question (source)
2015-12-06 04:43:41 -0500 received badge  Notable Question (source)
2015-10-13 15:09:12 -0500 received badge  Popular Question (source)
2015-07-19 17:27:38 -0500 received badge  Notable Question (source)
2015-07-05 22:35:57 -0500 received badge  Popular Question (source)
2015-06-10 14:27:22 -0500 received badge  Popular Question (source)
2015-03-18 18:51:41 -0500 received badge  Student (source)
2015-03-12 07:33:05 -0500 received badge  Popular Question (source)
2014-12-09 14:04:58 -0500 marked best answer Calculates the angle of orientation of the image with the gradient method

Hello, I have an image I applied the gradient method for the orientation angle of the latter. following the execution of this code I images for gradient directions Dx and DY. So I need to find the orientation angle. Personally I do not know where is the problem because I have no error! Please help me

  #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>

    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/imgproc/imgproc.hpp"
    #include "opencv2/core/core.hpp"

    using namespace std;
    using namespace cv;
    //#include "Functions.h"
    int main()
    {
    Mat image;
    //image = imread("lena.jpg",1);
    image = imread("uEyeImg0.tif",1);
    if(image.empty())
    {
    cout << "Could not open or find the image" << std::endl ;
    return -1;
    }

    /// Convert it to gray
    //cvtColor( image, image, CV_RGB2GRAY );
    //resize(image,image,Size(0,0),0.5,0.5,INTER_LINEAR);
    namedWindow("Image", CV_WINDOW_AUTOSIZE );
    imshow("Image", image);
    /// Generate grad_x and grad_y
    Mat grad_x, grad_y;
    Mat abs_grad_x, abs_grad_y;
    int scale = 1;
    int delta = 0;
    int ddepth = CV_16S;
    Mat grad;


    /// Gradient X
    //Scharr( image, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT );
    Sobel( image, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );
    convertScaleAbs( grad_x, abs_grad_x );

    /// Gradient Y
    // Scharr( image, grad_y, ddepth, 0, 1, scale, delta, BORDER_DEFAULT );
    Sobel( image, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );
    convertScaleAbs( grad_y, abs_grad_y );
    /// Total Gradient (approximate)

    addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad );




     Mat orientation = Mat(abs_grad_x.rows, abs_grad_y.cols, CV_32F); //to store the gradients
      Mat img=Mat(abs_grad_x.rows, abs_grad_y.cols, CV_32F);//to draw out the map
      img = cv::Scalar(255,255,255);//all white


     // Calculate orientations of gradients --> in degrees
    // Loop over all matrix values and calculate the accompanied orientation

     for(int i = 0; i < abs_grad_x.rows; i++){
        for(int j = 0; j < abs_grad_x.cols; j++){
            // Retrieve a single value

            float valueX = abs_grad_x.at<float>(i,j);
            float valueY = abs_grad_x.at<float>(i,j);
            // Calculate the corresponding single direction, done by applying the arctangens function
            float result = fastAtan2(valueX,valueY);
            // Store in orientation matrix element
            orientation.at<float>(i,j) = result;

        }
     }

    namedWindow("ImageSobel", CV_WINDOW_AUTOSIZE );
    imshow( "ImageSobel", grad );

    namedWindow("ImageSobelGx", CV_WINDOW_AUTOSIZE );
    imshow( "ImageSobelGx", abs_grad_x );

    namedWindow("ImageSobelGy", CV_WINDOW_AUTOSIZE );
    imshow( "ImageSobelGy", abs_grad_y );

    waitKey(0);
    return 0;
    }
2014-11-03 04:58:24 -0500 marked best answer How to cut an image in small images with opencv !!!

C:\fakepath\small image.jpgHello I need to cut an image in small images with opencv for my algo ! please help me . thank you

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

using namespace std;
using namespace cv;

int main()
{
Mat image;

image = imread("crop_uEyeImg1.tif",1);
if(image.empty())
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}

/// Convert it to gray
//cvtColor( image, image, CV_RGB2GRAY );
//resize(image,image,Size(0,0),0.5,0.5,INTER_LINEAR);
namedWindow("Image", CV_WINDOW_AUTOSIZE );
imshow("Image", image);
/// Generate grad_x and grad_y
Mat grad_x, grad_y;
Mat abs_grad_x, abs_grad_y;
int scale = 1;
int delta = 0;
int ddepth = CV_16S;
Mat grad;

   // get the image data
 int height = image.rows;
 int width = image.cols;

 printf("Processing a %dx%d image\n",height,width);

cv :: Size smallSize ( 110 , 70 );

std :: vector < Mat > smallImages ;


for  ( int y =  0 ; y < image . rows ; y += smallSize . height )
{
    for  ( int x =  0 ; x < image . cols ; x += smallSize . width )
    {
        cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );
        smallImages . push_back ( cv :: Mat ( image , rect ));



///// Gradient X
////Scharr( image, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT );
Sobel( image, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );
convertScaleAbs( grad_x, abs_grad_x );

///// Gradient Y
//// Scharr( image, grad_y, ddepth, 0, 1, scale, delta, BORDER_DEFAULT );
Sobel( image, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );
convertScaleAbs( grad_y, abs_grad_y );
///// Total Gradient (approximate)

addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad );

namedWindow("ImageSobel", CV_WINDOW_AUTOSIZE );
imshow( "ImageSobel", grad );

namedWindow("ImageSobelGx", CV_WINDOW_AUTOSIZE );
imshow( "ImageSobelGx", abs_grad_x );

namedWindow("ImageSobelGy", CV_WINDOW_AUTOSIZE );
imshow( "ImageSobelGy", abs_grad_y );

// // Calculate orientations of gradients --> in degrees
// //Loop over all matrix values and calculate the accompanied orientation

Mat orientation = Mat::zeros(abs_grad_x.rows, abs_grad_y.cols, CV_32F); //to store the gradients

grad_x.convertTo(grad_x,CV_32F);
grad_y.convertTo(grad_y,CV_32F);
//phase(grad_x, grad_y, orientation);
//cv::normalize(orientation, orientation, 0x00, 0xFF, cv::NORM_MINMAX, CV_8U);

////namedWindow("Orientation", CV_WINDOW_AUTOSIZE );
////imshow( "Orientation", orientation );

phase(grad_x, grad_y, orientation, true);
ofstream file1("orient.txt"); file1 << orientation; file1.close();
  }
}
waitKey(0);
return 0;
}
2014-07-09 03:27:03 -0500 asked a question How can I Set and reset a bit for 10 ms !!

Hello ,

I would like set a bit and off for 10ms to send a command after my image processing !! think you

2014-07-01 02:23:54 -0500 commented answer Imread many image of type Mat

I did it as you told me but I have an error " segmentation fault" I've updated the code used

2014-06-30 10:10:39 -0500 asked a question Imread many image of type Mat

Hello , With my program I can read an image. Now I have many images in my database. How can I do read the image loop! (the type of image is Mat) Please! thank you

int main()
{
vector<Mat> frames;
char filename[100] ;
    for (int i=1;i<4;i++){
        sprintf(filename,"/home/user/Bureau/Nouveau dossier/sobel-test/uEyeImg000%d.tif",i);
        Mat frame=imread(filename);
        frames.push_back(frame);

    }
    waitKey(0);
     return 0 ;
}
2014-06-30 05:09:52 -0500 asked a question Crop image with opencv !!

Hello , I want to crop image while keeping the same "y" position and Height against by changing the "x" position and width!! Please help me Thank you

2014-06-30 03:17:04 -0500 commented answer Convert vector 2D of Mat type to vector 1D ?

thank you :)

2014-06-26 06:45:45 -0500 asked a question Convert vector 2D of Mat type to vector 1D ?

Hello I have a picture of Mat-type so it is a 2D vector. I want to convert it into a 1D vector. how can I do it knowing that I have already used this function it does not work?? please help me ..

/// Convert  mat Grad X  to vector
    vector< float> Vgrad_x;

    Vgrad_x.assignTo(smallImages_gradx,-1);
2014-06-25 02:01:01 -0500 commented answer Display 4 images and save as in a table (opencv , C++ )

thank you :) but the smallImages is declared like Mat . So I have an error when it is like a table smallImages[i] ..

2014-06-23 04:53:13 -0500 commented answer Display 4 images and save as in a table (opencv , C++ )

If you can do for me a small sample code for an image and divide it into 4 parts and then save the 4 small images. Because I can not follow you. I am a beginner and I'm really blocked for several days. Please update your code with a simple and complete example thank you

2014-06-23 01:52:43 -0500 commented answer Display 4 images and save as in a table (opencv , C++ )

many small images of the input image

2014-06-20 08:02:41 -0500 commented answer Display 4 images and save as in a table (opencv , C++ )

the new solution does not working . error in line imshow ( image_name [ i ], smallImages [ i ] ); and if I change this line by imshow ( image_name [ i ], cv :: Mat ( image , rect ) ); I got only the last image but i like to have all the value of images saved in a table.

2014-06-20 06:19:58 -0500 commented answer Display 4 images and save as in a table (opencv , C++ )

thank you but its not working

2014-06-20 03:43:38 -0500 commented answer Display 4 images and save as in a table (opencv , C++ )

I have in my code waitkey (0) ; but I have an error: declaration of ‘image_name’ as multidimensional array must have bounds for all dimensions except the first for the declaration of image_name !!

2014-06-20 02:56:42 -0500 asked a question Display 4 images and save as in a table (opencv , C++ )

Hello,

The code will read an image and cut into 4 parts so 4 small images. My problem is to display 4 images and save in a table.

I can display only the last image but not all with imshow : imshow ( "smallImages", cv::Mat ( image , rect ));

Please help me and think you.

for  ( int y =  0 ; y < image . rows ; y += smallSize . height )
    {
        for  ( int x =  0 ; x < image  . cols ; x += smallSize . width )
        {
            cv :: Rect rect =   cv :: Rect ( x , y , smallSize . width , smallSize . height );
            smallImages . push_back ( cv :: Mat ( image  , rect ));
            imshow ( "smallImages", cv::Mat ( image , rect ));

        }
    }
2014-06-18 06:35:31 -0500 commented question Problem of return value !!

I have the variable result type matrix that contains values ​​between [0,1] the goal is to return the min and max and their indices minLoc maxLoc I did this but it does not work as I want: if( match_method == TM_SQDIFF || match_method == TM_SQDIFF_NORMED ) { matchLoc = minLoc; printf ( " minVal=%0.1f\n",minVal); printf ( " minloc_x=%d\n",minLoc.x); printf ( " minloc_y=%d\n",minLoc.y);} else { matchLoc = maxLoc; printf ( " maxVal=%0.2f\n",maxVal); printf ( " maxloc_x=%d\n",maxLoc.x); printf ( " maxloc_y=%d\n",maxLoc.y);}

2014-06-18 03:46:33 -0500 asked a question Problem of return value !!

Hello, Please I need your help to extract the value of the minVal, maxVal and minLoc, maxLoc.

I have the variable result type matrix that contains values ​​between [0,1] the goal is to return the min and max and their indices minLoc maxLoc I did this but it does not work as I want:

Think you

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

using namespace std;
using namespace cv;


/// Global Variables
Mat img; Mat templ; Mat result;
Mat im_out;
Mat im_out1;
const char* image_window = "Source Image";
const char* result_window = "Result window";

int match_method;
int max_Trackbar = 5;


/// Function Headers
void MatchingMethod( int, void* );


/**
 * @function main
 */
int main( int, char** argv )
{
  /// Load image and template

  img = cvLoadImage("ref1.tif", CV_LOAD_IMAGE_GRAYSCALE);
  namedWindow("image_source");
  namedWindow("resize-image_source");
  resize(img,im_out,Size(img.cols/5,img.rows/5),0,0,INTER_LINEAR);
  imshow("image_source", img);
  imshow("resize-image_source", im_out);

  templ = cvLoadImage("tpl5.tif", CV_LOAD_IMAGE_GRAYSCALE);
  namedWindow("image_palette");
  namedWindow("resize-image_palette");
  resize(templ,im_out1,Size(templ.cols/5,templ.rows/5),0,0,INTER_LINEAR);
  imshow("image_source", img);
  imshow("resize-image_palette", im_out1);

  /// Create windows
  namedWindow( image_window, WINDOW_AUTOSIZE );
  namedWindow( result_window, WINDOW_AUTOSIZE );

  /// Create Trackbar
 const char* trackbar_label = "Method: \n 0: SQDIFF \n 1: SQDIFF NORMED \n 2: TM CCORR \n 3: TM CCORR NORMED \n 4: TM COEFF \n 5: TM COEFF NORMED";
 createTrackbar( trackbar_label, image_window, &match_method, 5, MatchingMethod );

  MatchingMethod( 0, 0 );

  waitKey(0);
  return 0;
}

/**
 * @function MatchingMethod
 * @brief Trackbar callback
 */
void MatchingMethod( int, void* )
{
    //char* window_name = "Image result hist ";

    string  name;

  /// Source image to display
  Mat img_display;
  im_out.copyTo( img_display );

  /// Create the result matrix
  int result_cols =  im_out.cols - im_out1.cols + 1;
  int result_rows = im_out.rows - im_out1.rows + 1;


  result.create( result_cols, result_rows, CV_32FC1 );

  /// Do the Matching and Normalize
  matchTemplate( im_out, im_out1, result, match_method );
  normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );


  /// Localizing the best match with minMaxLoc
  double minVal; double maxVal; Point minLoc; Point maxLoc;
  Point matchLoc;

  minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() );



  /// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better
   if( match_method  == TM_SQDIFF || match_method == TM_SQDIFF_NORMED )
{ matchLoc = minLoc;
 printf ( " minVal=%0.1f\n",minVal);
 printf ( " minloc_x=%d\n",minLoc.x);
 printf ( " minloc_y=%d\n",minLoc.y);}


 else
    { matchLoc = maxLoc;
       printf ( " maxVal=%0.2f\n",maxVal);
       printf ( " maxloc_x=%d\n",maxLoc.x);
       printf ( " maxloc_y=%d\n",maxLoc.y);}

  /// Show me what you got
  rectangle( img_display, matchLoc, Point( matchLoc.x + im_out1.cols , matchLoc.y + im_out1.rows ), Scalar::all(0), 2, 8, 0 );
  rectangle( result, matchLoc, Point( matchLoc.x + im_out1.cols , matchLoc.y + im_out1.rows ), Scalar::all(0), 2, 8, 0 );
  cout << "result = " << endl << " " << result<< endl << endl;
  printf ( " minVal=%d\n",minVal);
  printf ( " maxVal=%d\n",maxVal);

  imshow( image_window, img_display );
  imshow( result_window, result );



return;
}
2014-06-16 10:28:30 -0500 asked a question How can I return the result of the coorelation between [0,1] ?

Hello , I want to return the result of the coorelation between [0,1] for each methode . please help me think you

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

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


using namespace std;
using namespace cv;


/// Global Variables
Mat img; Mat templ; Mat result;
const char* image_window = "Source Image";
const char* result_window = "Result window";

int match_method;
int max_Trackbar = 5;

/// Function Headers
void MatchingMethod( int, void* );

/**
 * @function main
 */
int main( int, char** argv )
{
  /// Load image and template
  //img = imread( argv[1], 1 );
  //templ = imread( argv[2], 1 );

  img = cvLoadImage("ref1.jpg", CV_LOAD_IMAGE_GRAYSCALE);

  templ = cvLoadImage("tpl1.jpg", CV_LOAD_IMAGE_GRAYSCALE);

  //
  /// Create windows
  namedWindow( image_window, WINDOW_AUTOSIZE );
  namedWindow( result_window, WINDOW_AUTOSIZE );

  /// Create Trackbar
 const char* trackbar_label = "Method: \n 0: SQDIFF \n 1: SQDIFF NORMED \n 2: TM CCORR \n 3: TM CCORR NORMED \n 4: TM COEFF \n 5: TM COEFF NORMED";
 createTrackbar( trackbar_label, image_window, &match_method, 5, MatchingMethod );

  MatchingMethod( 0, 0 );

  waitKey(0);
  return 0;
}

/**
 * @function MatchingMethod
 * @brief Trackbar callback
 */
void MatchingMethod( int, void* )
{
  /// Source image to display
  Mat img_display;
  img.copyTo( img_display );

  /// Create the result matrix
  int result_cols =  img.cols - templ.cols + 1;
  int result_rows = img.rows - templ.rows + 1;

  result.create( result_cols, result_rows, CV_32FC1 );

  /// Do the Matching and Normalize
  matchTemplate( img, templ, result, match_method );
  normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );


  /// Localizing the best match with minMaxLoc
  double minVal; double maxVal; Point minLoc; Point maxLoc;
  Point matchLoc;

  minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() );


  /// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better
  if( match_method  == TM_SQDIFF || match_method == TM_SQDIFF_NORMED )
    { matchLoc = minLoc; }
  else
    { matchLoc = maxLoc; }

  /// Show me what you got
  rectangle( img_display, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );
  rectangle( result, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );

  imshow( image_window, img_display );
  imshow( result_window, result );

  return;
}
2014-06-16 10:21:18 -0500 asked a question How can I have only the method of "TM COEFF NORMED"?

enter code here

Hello, I want to use only the method of "TM COEFF NORMED" for the Demo code of "Template Matching". Please help me ... Think you

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

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


using namespace std;
using namespace cv;


/// Global Variables
Mat img; Mat templ; Mat result;
const char* image_window = "Source Image";
const char* result_window = "Result window";

int match_method;
int max_Trackbar = 5;

/// Function Headers
void MatchingMethod( int, void* );

/**
 * @function main
 */
int main( int, char** argv )
{
  /// Load image and template
  //img = imread( argv[1], 1 );
  //templ = imread( argv[2], 1 );

  img = cvLoadImage("ref1.jpg", CV_LOAD_IMAGE_GRAYSCALE);

  templ = cvLoadImage("tpl1.jpg", CV_LOAD_IMAGE_GRAYSCALE);

  //
  /// Create windows
  namedWindow( image_window, WINDOW_AUTOSIZE );
  namedWindow( result_window, WINDOW_AUTOSIZE );

  /// Create Trackbar
 const char* trackbar_label = "Method: \n 0: SQDIFF \n 1: SQDIFF NORMED \n 2: TM CCORR \n 3: TM CCORR NORMED \n 4: TM COEFF \n 5: TM COEFF NORMED";
 createTrackbar( trackbar_label, image_window, &match_method, 5, MatchingMethod );

  MatchingMethod( 0, 0 );

  waitKey(0);
  return 0;
}

/**
 * @function MatchingMethod
 * @brief Trackbar callback
 */
void MatchingMethod( int, void* )
{
  /// Source image to display
  Mat img_display;
  img.copyTo( img_display );

  /// Create the result matrix
  int result_cols =  img.cols - templ.cols + 1;
  int result_rows = img.rows - templ.rows + 1;

  result.create( result_cols, result_rows, CV_32FC1 );

  /// Do the Matching and Normalize
  matchTemplate( img, templ, result, match_method );
  normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );


  /// Localizing the best match with minMaxLoc
  double minVal; double maxVal; Point minLoc; Point maxLoc;
  Point matchLoc;

  minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() );


  /// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better
  if( match_method  == TM_SQDIFF || match_method == TM_SQDIFF_NORMED )
    { matchLoc = minLoc; }
  else
    { matchLoc = maxLoc; }

  /// Show me what you got
  rectangle( img_display, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );
  rectangle( result, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );

  imshow( image_window, img_display );
  imshow( result_window, result );

  return;
}