Skip to content
Snippets Groups Projects
Select Git revision
  • cb1826076676a851c63868207e01ede07a552c02
  • master default protected
  • beta
  • dev
  • andrewssobral-patch-1
  • update
  • thomas-fork
  • 2.0
  • v3.2.0
  • v3.1.0
  • v3.0
  • bgslib_py27_ocv3_win64
  • bgslib_java_2.0.0
  • bgslib_console_2.0.0
  • bgslib_matlab_win64_2.0.0
  • bgslib_qtgui_2.0.0
  • 2.0.0
  • bgs_console_2.0.0
  • bgs_matlab_win64_2.0.0
  • bgs_qtgui_2.0.0
  • v1.9.2_x86_mfc_gui
  • v1.9.2_x64_java_gui
  • v1.9.2_x86_java_gui
23 results

ttoolbox.cpp

Blame
  • user avatar
    Thomas Boy authored
    cb182607
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ttoolbox.cpp 3.32 KiB
    #include "ttoolbox.h"
    
    std::string TToolBox::mNzero(int i)
    {
        std::ostringstream convert;
        convert << i ;
        std::string numberString = convert.str();
        std::string newNumberString = std::string(10 - numberString.length(), '0') + numberString;
        return newNumberString;
    }
    std::string TToolBox::getFileName(int i)
    {
        std::string fileName =std::string ( std::string ("/data/")+  mNzero(i) + std::string (".jpg"));
        return fileName;
    }
    
    std::vector<std::vector<cv::Point>> TToolBox::applyCannyEdgeAndCalcCountours(cv::Mat imgSource, double threshholdMin, double threshholdMax, int apertureSize)
    {
        cv::Mat imgCannyEdge;
        std::vector<std::vector<cv::Point> > contours;
        std::vector<cv::Vec4i> hierarchy;
    
        //! 2 make a copy
        cv::Mat imgBinary = imgSource.clone();
        //imgMarkBinary = Scalar(255,255,255); //fill white
    
        //! 3 apply binary filter not reduce noise
        //method to threshold important changes
        int binaryThreshold = 80; //TODO as parameter
        imgBinary = imgSource > binaryThreshold;
    
    
        //! 4 smooth with gaussian filter to suppress no connected lines
        //add a gaussian filter //see http://docs.opencv.org/2.4/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.html
        cv::Mat imgSmoothed = imgBinary.clone();
        int exclusPara3 = 3; //TODO as parameter
        cv::GaussianBlur(imgBinary,imgSmoothed,cv::Size(exclusPara3,exclusPara3),0);  //0 = BORDER_CONSTANT
    
        //! 5 we make the canny edge detect
        // Detect edges using canny
        cv::Canny( imgSmoothed, imgCannyEdge, threshholdMin, threshholdMax, apertureSize );
    
        // Find contours, use RETR_EXTERNAL ignore inner child structures, TREE more usefull ?
        cv::findContours( imgCannyEdge, contours, hierarchy, cv::RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0) );
    
    #ifdef  MC_SHOW_STEP_ANALYSE
        // Draw contours on extra mat
        Mat imgContour = Mat::zeros( imgCannyEdge.size(), CV_8UC3 );
        imgContour =  Scalar(255,255,255); //fille the picture
        RNG rng(232323);
        for( size_t i = 0; i< contours.size(); i++ )
        {
            //random color
            Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
            //contour
            drawContours( imgContour, contours, i, color, 1, LINE_AA, hierarchy, 0, Point() );
        }
    
        cv::String outpath=  "/homes/tb55xemi/work/bugTrainingSet/testRec/rec04379437pp/result/";
        std::ostringstream convert;
        convert << outpath << frameCounter <<"_countour_canny_edge.jpg";
        cv::imwrite(convert.str().c_str(), imgContour);
    
    #endif
    
        //    return minRect;
        return contours;
    }
    
    
    cv::Mat TToolBox::cropImageCircle(cv::Mat image, int x, int y, int r)
    {
    
        // Your Hough circle
        cv::Vec3f circ(x,y,r);
    
        // Draw the mask: white circle on black background
        cv::Mat1b mask(image.size(), uchar(0));
        cv::circle(mask, cv::Point(circ[0], circ[1]), circ[2], cv::Scalar(255), CV_FILLED);
    
        //NO CROP NEEDED
    
        // Compute the bounding box
        //Rect bbox(circ[0] - circ[2], circ[1] - circ[2], 2 * circ[2], 2 * circ[2]);
    
        // Create a black image
        cv::Mat res = cv::Mat::zeros( image.size(), CV_8UC3 );
        res = cv::Scalar(0,0,0); //fill with black color
    
    
        // Copy only the image under the white circle to black image
        image.copyTo(res, mask);
    
        // Crop according to the roi
        //res = res(bbox);
    
        return res;
    }