青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

OpenCV detect partial circle with noise

https://stackoverflow.com/questions/26222525/opencv-detect-partial-circle-with-noise

using this as input (your own median filtered image (I've just cropped it):

enter image description here

First I "normalize" the image. I just stretch values, that smallest val is 0 and biggest val is 255, leading to this result: (maybe some real contrast enhancement is better)

enter image description here

after that I compute the threshold of that image with some fixed threshold (you might need to edit that and find a way to choose the threshold dynamically! a better contrast enhancement might help there)

enter image description here

from this image, I use some simple RANSAC circle detection(very similar to my answer in the linked semi-circle detection question), giving you this result as a best semi-sircle:

enter image description here

int main()


{

    //cv::Mat color = cv::imread("../inputData/semi_circle_contrast.png");

    cv::Mat color = cv::imread("../inputData/semi_circle_median.png");

    cv::Mat gray;

 

    // convert to grayscale

    cv::cvtColor(color, gray, CV_BGR2GRAY);

 

    // now map brightest pixel to 255 and smalles pixel val to 0. this is for easier finding of threshold

    double min, max;

    cv::minMaxLoc(gray,&min,&max);

    float sub = min;

    float mult = 255.0f/(float)(max-sub);

    cv::Mat normalized = gray - sub;

    normalized = mult * normalized;

    cv::imshow("normalized" , normalized);

    //--------------------------------

 

 

    // now compute threshold

    // TODO: this might ne a tricky task if noise differs...

    cv::Mat mask;

    //cv::threshold(input, mask, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);

    cv::threshold(normalized, mask, 100, 255, CV_THRESH_BINARY);

 

 

 

    std::vector<cv::Point2f> edgePositions;

    edgePositions = getPointPositions(mask);

 

    // create distance transform to efficiently evaluate distance to nearest edge

    cv::Mat dt;

    cv::distanceTransform(255-mask, dt,CV_DIST_L1, 3);

 

    //TODO: maybe seed random variable for real random numbers.

 

    unsigned int nIterations = 0;

 

    cv::Point2f bestCircleCenter;

    float bestCircleRadius;

    float bestCirclePercentage = 0;

    float minRadius = 50;   // TODO: ADJUST THIS PARAMETER TO YOUR NEEDS, otherwise smaller circles wont be detected or "small noise circles" will have a high percentage of completion

 

    //float minCirclePercentage = 0.2f;

    float minCirclePercentage = 0.05f;  // at least 5% of a circle must be present? maybe more...

 

    int maxNrOfIterations = edgePositions.size();   // TODO: adjust this parameter or include some real ransac criteria with inlier/outlier percentages to decide when to stop

 

    for(unsigned int its=0; its< maxNrOfIterations; ++its)

    {

        //RANSAC: randomly choose 3 point and create a circle:

        //TODO: choose randomly but more intelligent,

        //so that it is more likely to choose three points of a circle.

        //For example if there are many small circles, it is unlikely to randomly choose 3 points of the same circle.

        unsigned int idx1 = rand()%edgePositions.size();

        unsigned int idx2 = rand()%edgePositions.size();

        unsigned int idx3 = rand()%edgePositions.size();

 

        // we need 3 different samples:

        if(idx1 == idx2) continue;

        if(idx1 == idx3) continue;

        if(idx3 == idx2) continue;

 

        // create circle from 3 points:

        cv::Point2f center; float radius;

        getCircle(edgePositions[idx1],edgePositions[idx2],edgePositions[idx3],center,radius);

 

        // inlier set unused at the moment but could be used to approximate a (more robust) circle from alle inlier

        std::vector<cv::Point2f> inlierSet;

 

        //verify or falsify the circle by inlier counting:

        float cPerc = verifyCircle(dt,center,radius, inlierSet);

 

        // update best circle information if necessary

        if(cPerc >= bestCirclePercentage)

            if(radius >= minRadius)

        {

            bestCirclePercentage = cPerc;

            bestCircleRadius = radius;

            bestCircleCenter = center;

        }

 

    }

 

    // draw if good circle was found

    if(bestCirclePercentage >= minCirclePercentage)

        if(bestCircleRadius >= minRadius);

        cv::circle(color, bestCircleCenter,bestCircleRadius, cv::Scalar(255,255,0),1);

 

 

        cv::imshow("output",color);

        cv::imshow("mask",mask);

        cv::waitKey(0);

 

        return 0;

    }

 

float verifyCircle(cv::Mat dt, cv::Point2f center, float radius, std::vector<cv::Point2f> & inlierSet)
{
 unsigned int counter = 0;
 unsigned int inlier = 0;
 float minInlierDist = 2.0f;
 float maxInlierDistMax = 100.0f;
 float maxInlierDist = radius/25.0f;
 if(maxInlierDist<minInlierDist) maxInlierDist = minInlierDist;
 if(maxInlierDist>maxInlierDistMax) maxInlierDist = maxInlierDistMax;
 
 // choose samples along the circle and count inlier percentage
 for(float t =0; t<2*3.14159265359f; t+= 0.05f)
 {
     counter++;
     float cX = radius*cos(t) + center.x;
     float cY = radius*sin(t) + center.y;
 
     if(cX < dt.cols)
     if(cX >= 0)
     if(cY < dt.rows)
     if(cY >= 0)
     if(dt.at<float>(cY,cX) < maxInlierDist)
     {
        inlier++;
        inlierSet.push_back(cv::Point2f(cX,cY));
     }
 }
 
 return (float)inlier/float(counter);
}
 
 
inline void getCircle(cv::Point2f& p1,cv::Point2f& p2,cv::Point2f& p3, cv::Point2f& center, float& radius)
{
  float x1 = p1.x;
  float x2 = p2.x;
  float x3 = p3.x;
 
  float y1 = p1.y;
  float y2 = p2.y;
  float y3 = p3.y;
 
  // PLEASE CHECK FOR TYPOS IN THE FORMULA :)
  center.x = (x1*x1+y1*y1)*(y2-y3) + (x2*x2+y2*y2)*(y3-y1) + (x3*x3+y3*y3)*(y1-y2);
  center.x /= ( 2*(x1*(y2-y3) - y1*(x2-x3) + x2*y3 - x3*y2) );
 
  center.y = (x1*x1 + y1*y1)*(x3-x2) + (x2*x2+y2*y2)*(x1-x3) + (x3*x3 + y3*y3)*(x2-x1);
  center.y /= ( 2*(x1*(y2-y3) - y1*(x2-x3) + x2*y3 - x3*y2) );
 
  radius = sqrt((center.x-x1)*(center.x-x1) + (center.y-y1)*(center.y-y1));
}
 
 
 
std::vector<cv::Point2f> getPointPositions(cv::Mat binaryImage)
{
 std::vector<cv::Point2f> pointPositions;
 
 for(unsigned int y=0; y<binaryImage.rows; ++y)
 {
     //unsigned char* rowPtr = binaryImage.ptr<unsigned char>(y);
     for(unsigned int x=0; x<binaryImage.cols; ++x)
     {
         //if(rowPtr[x] > 0) pointPositions.push_back(cv::Point2i(x,y));
         if(binaryImage.at<unsigned char>(y,x) > 0) pointPositions.push_back(cv::Point2f(x,y));
     }
 }
 
 return pointPositions;
}

 

posted on 2017-10-17 13:39 zmj 閱讀(930) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美精品一区三区| 亚洲综合导航| 国产专区综合网| 欧美一级网站| 亚洲欧美一区二区三区在线| 欧美日韩一级大片网址| 欧美激情一区二区| 久久久精品2019中文字幕神马| 激情亚洲成人| 欧美日韩一区成人| 欧美华人在线视频| 亚洲美女一区| 美女精品在线观看| 免费一区二区三区| 亚洲欧美精品在线观看| 欧美不卡高清| 在线精品一区二区| 国产精品综合不卡av| 精品91在线| 亚洲日本aⅴ片在线观看香蕉| 欧美性猛片xxxx免费看久爱 | 国产亚洲视频在线| 日韩视频在线观看国产| 麻豆精品一区二区综合av| 午夜久久久久久久久久一区二区| 亚洲剧情一区二区| 激情小说另类小说亚洲欧美| 欧美日韩人人澡狠狠躁视频| 欧美久久一级| 久久婷婷色综合| 欧美高清视频在线观看| 国产精品久久久久久久久久ktv| 国产欧美欧美| 好吊色欧美一区二区三区视频| 日韩香蕉视频| 久久不射2019中文字幕| 亚洲欧洲另类| 久久精品官网| 久久另类ts人妖一区二区| 亚洲一级影院| 久久综合狠狠综合久久综青草| 国产日韩欧美不卡在线| 国产精品久久网| 久久av红桃一区二区小说| 一区二区三区四区五区在线| 久久久99精品免费观看不卡| 国产日韩在线一区| 国产欧美综合一区二区三区| 亚洲欧洲久久| 亚洲社区在线观看| 欧美一级视频| 欧美激情在线免费观看| 9色国产精品| 亚洲第一网站| 91久久综合| 欧美日韩视频不卡| 国产精品日韩一区二区| av成人福利| 羞羞漫画18久久大片| 日韩写真视频在线观看| 亚洲影院免费观看| 国产精品―色哟哟| 久久久精彩视频| 亚洲国内自拍| 欧美屁股在线| 久久se精品一区二区| 性色av一区二区三区在线观看| 欧美午夜三级| 亚洲福利视频网站| 一区二区三区高清| 久久躁狠狠躁夜夜爽| 亚洲国产成人av好男人在线观看| 欧美大片在线看| 欧美日韩网址| 久久激情久久| 久久久久久国产精品mv| 亚洲电影中文字幕| 国产精品视频网站| 亚洲第一色在线| 国内精品**久久毛片app| 亚洲第一中文字幕在线观看| 久久九九精品99国产精品| 亚洲欧美日韩另类| 欧美在线啊v一区| 亚洲清纯自拍| 久久大逼视频| 91久久精品美女| 女仆av观看一区| 欧美1区免费| 国产精品美女久久久久久免费 | 国产精品区一区二区三| 最新国产の精品合集bt伙计| 99re6这里只有精品| 欧美午夜久久| 久久久久久国产精品mv| 国产精品乱码久久久久久| 欧美bbbxxxxx| 一区二区在线不卡| 性欧美暴力猛交69hd| 99re在线精品| 精品动漫一区二区| 亚洲视频在线二区| 这里是久久伊人| 国产精品国产三级国产a| 99在线精品免费视频九九视| 亚洲电影激情视频网站| 91久久精品国产91性色tv| 日韩午夜电影av| 欧美中文在线观看| 亚洲美女网站| 国产美女高潮久久白浆| 亚洲一区二区免费| 蜜臀av一级做a爰片久久 | 亚洲一区在线免费观看| 欧美日本不卡高清| 亚洲电影中文字幕| 午夜影视日本亚洲欧洲精品| 欧美日韩免费观看一区二区三区| 亚洲国产成人av好男人在线观看| 亚洲人久久久| 精品99一区二区三区| 农夫在线精品视频免费观看| 老司机免费视频久久| 欧美在线免费| 亚洲免费成人av| 国产喷白浆一区二区三区| 欧美美女福利视频| 久久精品日韩欧美| 亚洲一区二区三区在线看| 久久频这里精品99香蕉| 亚洲美女精品成人在线视频| 激情伊人五月天久久综合| 欧美a级大片| 一区二区三区黄色| 亚洲天堂黄色| 99国产精品国产精品久久| 韩国一区电影| 国产亚洲a∨片在线观看| 亚洲欧美日韩视频一区| 久久se精品一区精品二区| 日韩一级精品| 亚洲欧美国产制服动漫| 亚洲视频www| 国产精品xvideos88| 99在线精品视频| 亚洲国产99| 欧美日韩亚洲高清| 亚洲精品国产视频| 亚洲激情在线激情| 亚洲专区一区二区三区| 亚洲免费观看在线观看| 亚洲网址在线| 欧美国产乱视频| 国产精品久久久久秋霞鲁丝| 国产日韩欧美精品综合| 国产伦理一区| 亚洲欧洲精品一区二区精品久久久| 欧美午夜精品久久久久久人妖 | 亚洲——在线| 久久精品麻豆| 国产一区二区激情| 黄网动漫久久久| 中文日韩在线视频| 欧美成人嫩草网站| 欧美伊久线香蕉线新在线| 蜜桃av综合| 国产一区二区三区在线观看网站 | 卡通动漫国产精品| 老司机精品久久| 国产精品视频观看| 亚洲精品免费在线播放| 艳女tv在线观看国产一区| 亚洲欧洲一区二区天堂久久| 久久精品亚洲乱码伦伦中文| 欧美激情aⅴ一区二区三区| 亚洲精品一区二区三| 欧美日韩国产欧美日美国产精品| 欧美韩日高清| 久久裸体视频| 亚洲福利国产精品| 欧美成人午夜视频| 欧美专区第一页| 欧美日韩国产bt| 亚洲小说欧美另类婷婷| 欧美亚洲在线视频| 国产欧美日韩视频| 亚洲香蕉网站| 99精品久久| 国产性猛交xxxx免费看久久| 久久精品日韩欧美| 欧美国产一区二区在线观看 | 麻豆乱码国产一区二区三区| 久久综合伊人77777尤物| 欧美在线观看天堂一区二区三区| 国产精品高清在线观看| 99热免费精品| 牛夜精品久久久久久久99黑人| 国产亚洲精品资源在线26u| 另类激情亚洲| 国产精品户外野外|