Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Corner detection after edge detection

I have used canny edge detection using the following code :

        blur( src, src_gray, Size(3,3) );
        Canny( src_gray, detected_edges, 20, 40, kernel_size );
        dst = Scalar::all(0);
        src.copyTo(dst,detected_edges);

This give me the right edged form , but if i use corner detection by taking the variable dst as input array for corner detection, i get exception although have converted dst to float type 32:

        dst.convertTo(temp, CV_32FC1); 
        cornerHarris( temp, dst, blockSize, apertureSize, k, BORDER_DEFAULT );
       normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
        convertScaleAbs( dst_norm, dst_norm_scaled );

        /// Drawing a circle around corners
        for( int j = 0; j < dst_norm.rows ; j++ )
        {
            for( int i = 0; i < dst_norm.cols; i++ )
            {
               if( (int) dst_norm.at<float>(j,i) > thresh )
               {
                      circle( dst_norm_scaled, Point( i, j ), 5,  Scalar(0), 2, 8, 0 );
          count++;
          }
      }
 }

Corner detection after edge detection

I have used canny edge detection using the following code :

        blur( src, src_gray, Size(3,3) );
        Canny( src_gray, detected_edges, 20, 40, kernel_size );
        dst = Scalar::all(0);
        src.copyTo(dst,detected_edges);

This give me the right edged form , but if i use corner detection by taking the variable dst as input array for corner detection, i get exception although have converted dst to float type 32:

        dst.convertTo(temp, CV_32FC1); 
        cornerHarris( temp, dst, blockSize, apertureSize, k, BORDER_DEFAULT );
       normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
        convertScaleAbs( dst_norm, dst_norm_scaled );

        /// Drawing a circle around corners
        for( int j = 0; j < dst_norm.rows ; j++ )
        {
            for( int i = 0; i < dst_norm.cols; i++ )
            {
               if( (int) dst_norm.at<float>(j,i) > thresh )
               {
                      circle( dst_norm_scaled, Point( i, j ), 5,  Scalar(0), 2, 8, 0 );
          count++;
          }
      }
 }

I m using visual studio and it shows something like this:

image description

P.S: if i use the detected_edges variable instead of dst , i get no exception but wrong image: original image:

image description

result:

image description

Corner detection after edge detection

I have used canny edge detection using the following code :

        blur( src, src_gray, Size(3,3) );
        Canny( src_gray, detected_edges, 20, 40, kernel_size );
        dst = Scalar::all(0);
        src.copyTo(dst,detected_edges);

This give me the right edged form , but if i use corner detection by taking the variable dst as input array for corner detection, i get exception although have converted dst to float type 32:

        dst.convertTo(temp, CV_32FC1); 
        cornerHarris( temp, dst, blockSize, apertureSize, k, BORDER_DEFAULT );
       normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
        convertScaleAbs( dst_norm, dst_norm_scaled );

        /// Drawing a circle around corners
        for( int j = 0; j < dst_norm.rows ; j++ )
        {
            for( int i = 0; i < dst_norm.cols; i++ )
            {
               if( (int) dst_norm.at<float>(j,i) > thresh )
               {
                      circle( dst_norm_scaled, Point( i, j ), 5,  Scalar(0), 2, 8, 0 );
          count++;
          }
      }
 }

I m using visual studio and it shows something like this:

image description

P.S: if i use the detected_edges variable instead of dst , i get no exception but wrong image: original image:

image description

result:

image description

SCREENSHOT Showing exception:

image description

Corner detection after edge detection

I have used canny edge detection using the following code :

        blur( src, src_gray, Size(3,3) );
        Canny( src_gray, detected_edges, 20, 40, kernel_size );
        dst = Scalar::all(0);
        src.copyTo(dst,detected_edges);

This give me the right edged form , but if i use corner detection by taking the variable dst as input array for corner detection, i get exception although have converted dst to float type 32:

        dst.convertTo(temp, CV_32FC1); 
        cornerHarris( temp, dst, blockSize, apertureSize, k, BORDER_DEFAULT );
       normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
        convertScaleAbs( dst_norm, dst_norm_scaled );

        /// Drawing a circle around corners
        for( int j = 0; j < dst_norm.rows ; j++ )
        {
            for( int i = 0; i < dst_norm.cols; i++ )
            {
               if( (int) dst_norm.at<float>(j,i) > thresh )
               {
                      circle( dst_norm_scaled, Point( i, j ), 5,  Scalar(0), 2, 8, 0 );
          count++;
          }
      }
 }

I m using visual studio and it shows something like this:

image description

P.S: if i use the detected_edges variable instead of dst , i get no exception but wrong image: original image:

image description

result:

image description

SCREENSHOT Showing exception:

image description

                                Mat dst, dst_norm, dst_norm_scaled;
                //dst = Mat::zeros( src.size(), CV_32FC1 );
                temp = Mat::zeros( src.size(), CV_32FC1 );

                  /// Detector parameters
                int blockSize = 3;
                int apertureSize = 3;
                double k = 0.04;
                blur( src_gray, detected_edges, Size(3,3) );
                Canny( detected_edges, detected_edges, 20, 40, kernel_size );
                   dst = Scalar::all(0);
                   detected_edges.convertTo(detected_edges,CV_8U);
                   src.convertTo(src, CV_8UC1);
                   src.copyTo(dst,detected_edges);
                try{
                cornerHarris( dst, temp, blockSize, apertureSize, k, BORDER_DEFAULT );

                /// Normalizing
                 normalize( temp, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
                     convertScaleAbs( dst_norm, dst_norm_scaled );
                  /// Drawing a circle around corners
                for( int j = 0; j < dst_norm.rows ; j++ )
                    { for( int i = 0; i < dst_norm.cols; i++ )
                          {
                                if( (int) dst_norm.at<float>(j,i) > thresh )
                                    {
                                        circle( dst_norm_scaled, Point( i, j ), 5,  Scalar(0), 2, 8, 0 );
                                    }
                          }
                    }
                namedWindow( corners_window, CV_WINDOW_AUTOSIZE );
                imshow( corners_window, dst_norm_scaled );
                }
                catch(Exception e)
                {
                    e.err;
                }

Corner detection after edge detection

I have used canny edge detection using the following code :

        blur( src, src_gray, Size(3,3) );
        Canny( src_gray, detected_edges, 20, 40, kernel_size );
        dst = Scalar::all(0);
        src.copyTo(dst,detected_edges);

This give me the right edged form , but if i use corner detection by taking the variable dst as input array for corner detection, i get exception although have converted dst to float type 32:

        dst.convertTo(temp, CV_32FC1); 
        cornerHarris( temp, dst, blockSize, apertureSize, k, BORDER_DEFAULT );
       normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
        convertScaleAbs( dst_norm, dst_norm_scaled );

        /// Drawing a circle around corners
        for( int j = 0; j < dst_norm.rows ; j++ )
        {
            for( int i = 0; i < dst_norm.cols; i++ )
            {
               if( (int) dst_norm.at<float>(j,i) > thresh )
               {
                      circle( dst_norm_scaled, Point( i, j ), 5,  Scalar(0), 2, 8, 0 );
          count++;
          }
      }
 }

I m using visual studio and it shows something like this:

image description

P.S: if i use the detected_edges variable instead of dst , i get no exception but wrong image: original image:

image description

result:

image description

SCREENSHOT Showing exception:

image description

                                Mat dst, dst_norm, dst_norm_scaled;
                //dst = Mat::zeros( src.size(), CV_32FC1 );
                temp = Mat::zeros( src.size(), CV_32FC1 );

                  /// Detector parameters
                int blockSize = 3;
                int apertureSize = 3;
                double k = 0.04;
                blur( src_gray, detected_edges, Size(3,3) );
                Canny( detected_edges, detected_edges, 20, 40, kernel_size );
                   dst = Scalar::all(0);
                   detected_edges.convertTo(detected_edges,CV_8U);
                   src.convertTo(src, CV_8UC1);
                   src.copyTo(dst,detected_edges);
                try{
                cornerHarris( dst, temp, blockSize, apertureSize, k, BORDER_DEFAULT );

                /// Normalizing
                 normalize( temp, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
                     convertScaleAbs( dst_norm, dst_norm_scaled );
                  /// Drawing a circle around corners
                for( int j = 0; j < dst_norm.rows ; j++ )
                    { for( int i = 0; i < dst_norm.cols; i++ )
                          {
                                if( (int) dst_norm.at<float>(j,i) > thresh )
                                    {
                                        circle( dst_norm_scaled, Point( i, j ), 5,  Scalar(0), 2, 8, 0 );
                                    }
                          }
                    }
                namedWindow( corners_window, CV_WINDOW_AUTOSIZE );
                imshow( corners_window, dst_norm_scaled );
                }
                catch(Exception e)
                {
                    e.err;
                }