Ask Your Question

josealberto.fuentes's profile - activity

2017-08-20 21:04:19 -0600 received badge  Notable Question (source)
2016-06-02 13:42:08 -0600 received badge  Popular Question (source)
2015-03-02 00:38:54 -0600 asked a question Rotate rectangle with Emgu.cv

Hi,

I'm using a simple algorithm ( You cand find the algorithm in another question ) to find rectangles. I get the rectangles correctly.

The question is, What is the best way to rotate these rectangles in order to ensure that the segments of the rectangle are parallel respect to the axes?

Thanks,

2013-11-28 07:02:17 -0600 commented answer Problem inverting video

Thank you very much!! It works perfectly.

2013-11-28 07:01:09 -0600 received badge  Scholar (source)
2013-11-28 07:01:08 -0600 received badge  Supporter (source)
2013-11-28 06:26:58 -0600 asked a question Problem inverting video

Hi everybody,

I'm trying to invert a video that I'm reading from .avi file. This is my code:

#include "stdafx.h" 
#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

cv::Mat aFrameMatrix;    /**< Original Frame Matrix */
cv::Mat anOutputMatrix;  /**< Output Frame Matrix */

String anInputPath;      /**< Input video path */
String anOutputPath;     /**< Output video path */   
bool anExit = true;      /**< Exit application */

vector<cv::Mat>   matCollection;

int main( )
{ 
    std::cout << "  Invert Video:  " << std::endl;
    std::cout << "------------------------" << std::endl;
    std::cout << "* Enter the input video path : "; std::cin >> anInputPath;
    std::cout << "* Enter the output video path : "; std::cin >> anOutputPath;
    std::cout << "\n";  

    cv::VideoCapture anInputCapture( anInputPath );

    if ( !anInputCapture.isOpened( ) )
    {
       std::cout << "!!! Input video could not be opened" << std::endl;
       return -1;
    }   

    cv::VideoWriter anOutputCapture( anOutputPath, 
                                     ( int ) anInputCapture.get( CV_CAP_PROP_FOURCC ),
                                     ( int ) anInputCapture.get( CV_CAP_PROP_FPS ),
                                     cv::Size( ( int ) anInputCapture.get( CV_CAP_PROP_FRAME_WIDTH ),
                                     ( int ) anInputCapture.get( CV_CAP_PROP_FRAME_HEIGHT ) ) );

    if ( !anOutputCapture.isOpened( ) )
    {
        std::cout << "!!! Output video could not be opened" << std::endl;
        return -1;
    }

    namedWindow( "INPUT VIDEO: " + anInputPath, WINDOW_AUTOSIZE );
    namedWindow( "OUTPUT VIDEO: " + anOutputPath, WINDOW_AUTOSIZE );   

    while( anExit )
    {
       if ( !anInputCapture.read( aFrameMatrix ) ) 
       {
          anExit = false;
       }
       else
       {
          matCollection.push_back( aFrameMatrix );

          imshow( "INPUT VIDEO: " + anInputPath, aFrameMatrix );               
       }

       if( waitKey( 30 ) >= 0 ) 
       {
          return -1;
       }
    }

    while( !matCollection.empty( ) )
    {       
        imshow( "OUTPUT VIDEO: " + anOutputPath, matCollection.back( ) );      

        anOutputCapture.write( matCollection.back( ) );

        matCollection.pop_back( );

        if( waitKey( 30 ) >= 0 ) 
        {
           return -1;
        }
    }

    anInputCapture.release( );
    anOutputCapture.release( );

return 0;
}

The input video lenght (input_video.avi) is 16 seconds. In "INPUT VIDEO" window I can see the input video correctly, but the "OUTPUT VIDEO" window only shows last frame of "INPUT VIDEO" during 16 seconds. At the end, I get an output_video.avi with the same duration that original video but It only shows the last frame that I saw in "OUTPUT VIDEO" window.

What is wrong?

Thanks,

2013-11-16 09:29:57 -0600 received badge  Editor (source)
2013-11-16 09:28:42 -0600 asked a question Real distance between points with emgu.cv

Hi everybody,

I'm new using opencv. I usually work with C# and I have installed Emgu.cv to use opencv (2.3.1) with C# on Visual Studio 2010. I have started to find shapes like rectangles using the next code:

static public Image< Bgr, Byte > getShapes( WriteableBitmap aWriteableBitmap )
        {
            BitmapEncoder anEncoder = new PngBitmapEncoder( );
            anEncoder.Frames.Add( BitmapFrame.Create( aWriteableBitmap ) );
            MemoryStream aMemoryStream = new MemoryStream( );
            anEncoder.Save( aMemoryStream );
            Bitmap aBitmap = new Bitmap( aMemoryStream );
            bool aFlagRectangle = false;

            Image< Bgr, Byte >   aSourceImage = new Image< Bgr, Byte >( aBitmap );
            Image< Gray, Byte >  aGrayImage   = aSourceImage.Convert< Gray, Byte >( ).PyrDown( ).PyrUp( );

            Gray aCannyThreshold              = new Gray( 180 );
            Gray aCannyThresholdLinking       = new Gray( 120 );
            Gray aMinThreshold                = new Gray( 50 );
            Gray aMaxThreshold                = new Gray( 255 );

            Image< Gray, Byte > aCannyImages  = aGrayImage.Convert< Gray, Byte >( ).Canny( aCannyThreshold, aCannyThresholdLinking ).ThresholdBinary( aMinThreshold, aMaxThreshold );

            aCannyImages._Dilate(2);

            LineSegment2D[ ] aLines           = aCannyImages.HoughLinesBinary( 1,               // Distance resolution in pixel-related units
                                                                               Math.PI / 45.0,  // Angle resolution measured in radians.
                                                                               10,              // Threshold
                                                                               20,              // Min Line width
                                                                               30               // Gap between lines
                                                                               )[0];            // Get the lines from the first channel

            List< MCvBox2D > aBoxList         = new List< MCvBox2D >( );

            using ( MemStorage aStorage = new MemStorage( ) )

            for ( Contour< System.Drawing.Point > aContours = aCannyImages.FindContours( Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_TC89_KCOS , Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, aStorage );
                    aContours != null;
                    aContours = aContours.HNext )
            {
                Contour< System.Drawing.Point > aCurrentContour = aContours.ApproxPoly( aContours.Perimeter * 0.05, aStorage );

                if ( aContours.Area > 75 ) // Only consider contours with area greater than 50
                {
                    if ( aCurrentContour.Total == 4 ) // The contour has 4 vertices.
                    {
                        bool aIsRectangle             = true;
                        System.Drawing.Point[ ] aPts  = aCurrentContour.ToArray( );
                        LineSegment2D[ ] anEdges      = Emgu.CV.PointCollection.PolyLine( aPts, true );

                        for ( int i = 0; i < anEdges.Length; i++ )
                        {
                            double anAngle = Math.Abs( anEdges[ ( i + 1 ) % anEdges.Length ].GetExteriorAngleDegree( anEdges[ i ] ) );

                            if ( anAngle < 60 || anAngle > 100 )
                            {
                                aIsRectangle    = false;
                                break;
                            }
                        }

                        if ( aIsRectangle && aBoxList.Capacity == 0 )
                        {
                            aBoxList.Add( aCurrentContour.GetMinAreaRect( ) );

                            aFlagRectangle = true;
                        }
                    }
                }
            }

            Image< Bgr, Byte > triangleRectangleImage = aCannyImages.Convert< Bgr, Byte >( );

            foreach ( MCvBox2D aBox in aBoxList )
            {
                triangleRectangleImage.Draw( aBox, new Bgr( System.Drawing.Color.Orange ), 2 );
            }

            return triangleRectangleImage;
        }
    }

During debugging, I have seen that I get an array with 4 points with X and Y coordinates (aPts). Then, my question is, It's possible to get the real distance between the points to know what are the real measures of the object). The distance from camera to object is 1 m. I attach a picture of the object captured. C:\fakepath\capture_emgucv.png

Thanks,