opencv中的椭圆拟合
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                opencv中的椭圆拟合
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                首先貼一個最簡單的程序:訪問:https://blog.csdn.net/guduruyu/article/details/70069426
//創建一個用于繪制圖像的空白圖 cv::Mat image = cv::Mat::ones(480, 640, CV_8UC3); //設置藍色背景 image.setTo(cv::Scalar(100, 0, 0)); //輸入擬合點 std::vector<cv::Point> points; points.push_back(cv::Point(200, 240)); points.push_back(cv::Point(300, 400)); points.push_back(cv::Point(400, 360)); points.push_back(cv::Point(500, 300)); points.push_back(cv::Point(500, 200)); points.push_back(cv::Point(300, 150)); //將擬合點繪制到空白圖上 for (int i = 0; i < points.size(); i++) { cv::circle(image, points[i], 5, cv::Scalar(0, 0, 255), 2, 8, 0); } //獲取擬合橢圓的外包圍矩形 cv::RotatedRect rotate_rect = cv::fitEllipse(points); //繪制擬合橢圓 cv::ellipse(image, rotate_rect, cv::Scalar(0, 255, 255), 2, 8); cv::imshow("image", image); cv::waitKey(0);其次,這里有關于opencv橢圓擬合的各種定義:https://blog.csdn.net/suky520/article/details/18601307
opencv中的橢圓通過RotatedRect來定義,其center(塊中心(x,y)), size(寬和高,寬小于高), angle(旋轉角)分別對應橢圓的中心,短軸和長軸,旋轉角度。?
RotatedRect box = fitEllipse(pointsf); //把那些長軸與短軸之比很多的那些橢圓剔除。 if( MAX(box.size.width, box.size.height) > MIN(box.size.width, box.size.height)*8 ) continue; //繪制輪廓 drawContours(cimage, contours, (int)i, Scalar::all(255), 1, 8); //繪制橢圓 ellipse(cimage, box, Scalar(0,0,255), 1, CV_AA); //繪制橢圓 // ellipse(cimage, box.center, box.size*0.5f, box.angle, 0, 360, Scalar(0,255,255), 1, CV_AA); //注意這里需要乘以0.5 最后,目前opencv3中支持三種橢圓擬合方式:fitEllipse,fitEllipseAMS,fitEllipseDirect,其中第三種來自《 Direct least squares fitting of ellipsees, Fitzgibbon, Pilu and Fischer in Fitzgibbon, A.W., Pilu, M., and Fischer R.B.,Proc. of the 13th Internation Conference on Pattern Recognition, pp 253–257, Vienna, 1996》可以訪問https://docs.opencv.org/trunk/de/dc7/fitellipse_8cpp-example.html
來看官方的橢圓擬合事例。?
參考鏈接:
1.?https://blog.csdn.net/suky520/article/details/18601307
2.?https://www.cnblogs.com/as3asddd/p/7455712.html
3. https://blog.csdn.net/u012566751/article/details/54345465?
4.?https://blog.csdn.net/guduruyu/article/details/70069426
總結
以上是生活随笔為你收集整理的opencv中的椭圆拟合的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 计算机软考论文分数,信息系统项目管理师论
 - 下一篇: 【OS学习笔记】二十七 保护模式八:任务