OpenCV 怎么按照从左到右、从上到下的顺序查找轮廓

mengyandelove 2019-05-28 10:22:26
加精
求大神指教,findContours()求实现
...全文
18483 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
寅卯甲乙 2021-02-26
  • 打赏
  • 举报
回复
wwwweeert
Amber381008 2021-02-05
  • 打赏
  • 举报
回复
https://kimcrowing.github.io/iptv/index.m3u
Amber381008 2021-02-05
  • 打赏
  • 举报
回复
https://kimcrowing.github.io/iptv/index.m3u
kingweng88 2020-12-22
  • 打赏
  • 举报
回复
看不懂,等大侠来解!
qq_42640001 2020-11-13
  • 打赏
  • 举报
回复
这个是啥东西
qq_51005039 2020-09-26
  • 打赏
  • 举报
回复
111111111
nobookworm 2020-09-18
  • 打赏
  • 举报
回复
厉害厉害。6666
chillonyang 2020-08-12
  • 打赏
  • 举报
回复
看天书一样啊
m0_49488657 2020-07-19
  • 打赏
  • 举报
回复
塔聚聚来PK
待续_1006 2020-06-29
  • 打赏
  • 举报
回复
厉害了我的哥
qq_33846034 2020-06-11
  • 打赏
  • 举报
回复
看看。。。。。。。
qq995492440 2020-06-10
  • 打赏
  • 举报
回复
感谢!!!!
weixin_48340472 2020-06-03
  • 打赏
  • 举报
回复
谢谢大佬
joe_free 2020-05-29
  • 打赏
  • 举报
回复
多谢大佬分享
yujidang8706 2020-05-25
  • 打赏
  • 举报
回复
n=0;
vector<Point> approx;
for (;idx>=0;idx=hierarchy[idx][0]) {
color=colors[idx%15];
// drawContours(smallImg,contours,idx,color,1,8,hierarchy);
approxPolyDP(Mat(contours[idx]), approx, arcLength(Mat(contours[idx]), true)*0.005, true);//0.005为将毛边拉直的系数
const Point* p = &approx[0];
int m=(int)approx.size();
polylines(smallImg, &p, &m, 1, true, color);
circle(smallImg,Point(p[0].x,p[0].y),3,color);
circle(smallImg,Point(p[1].x,p[1].y),2,color);
for (int i=2;i<m;i++) circle(smallImg,Point(p[i].x,p[i].y),1,color);
n++;
if (1==n) {
maxrect=boundingRect(Mat(contours[idx]));
} else {
brect=boundingRect(Mat(contours[idx]));
CvRect mr
chuang2013 2020-05-25
  • 打赏
  • 举报
回复
厉害了...
lcqwertyuiop 2020-05-24
  • 打赏
  • 举报
回复
看天书一样啊
RIO小哥 2020-04-15
  • 打赏
  • 举报
回复
https://blog.csdn.net/weixin_44517500/article/details/105517322
赵4老师 2019-05-30
  • 打赏
  • 举报
回复
我这段代码已经给出每个轮廓的boundingRect了,你自己编写一个排序函数,再调用sort不就结了。
赵4老师 2019-05-29
  • 打赏
  • 举报
回复
仅供参考:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
using namespace std;
using namespace cv;
Mat img,smallImg,gray,bw;
vector<Vec4i> hierarchy;
vector<vector<Point> > contours;
int threshval=128;
Rect r;
Rect maxrect,brect;
int idx,n;
const static Scalar colors[15]={
    CV_RGB(  0,  0,128),
    CV_RGB(  0,128,  0),
    CV_RGB(  0,128,128),
    CV_RGB(128,  0,  0),
    CV_RGB(128,  0,128),
    CV_RGB(128,128,  0),
    CV_RGB(128,128,128),
    CV_RGB(160,160,160),
    CV_RGB(  0,  0,255),
    CV_RGB(  0,255,  0),
    CV_RGB(  0,255,255),
    CV_RGB(255,  0,  0),
    CV_RGB(255,  0,255),
    CV_RGB(255,255,  0),
    CV_RGB(255,255,255),
};
Scalar color;
void gamma_correct(Mat& img, Mat& dst, double gamma) {
	Mat	temp;
	CvMat tmp;

	img.convertTo(temp,	CV_32FC1, 1.0/255.0, 0.0);
	tmp=temp;
	cvPow(&tmp,	&tmp, gamma);
	temp.convertTo(dst , CV_8UC1 , 255.0	, 0.0);
}
int main() {
    cvNamedWindow("display",1);
    img=imread("image.jpg",1);
    r.x=img.cols/10;
    r.y=img.rows/3;
    r.width=img.cols*8/10;
    r.height=img.rows*2/3;
    smallImg=img(r);
    cvtColor(smallImg,gray,CV_BGR2GRAY);
//  medianBlur(gray,gray,5);
    equalizeHist(gray,gray);
    gamma_correct(gray,gray,4.0);
    imshow("display",gray);
    waitKey(0);

	bw=(gray>threshval);
    imshow("display",bw);
    waitKey(0);

	Mat	Structure0=getStructuringElement(MORPH_RECT,Size(3,3));
    erode(bw,bw,Structure0,Point(-1,-1));
	Mat	Structure1=getStructuringElement(MORPH_RECT,Size(6,6));
    dilate(bw,bw,Structure1, Point(-1,-1));
    imshow("display",bw);
    waitKey(0);

    findContours(bw,contours,hierarchy,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);
    if (!contours.empty()&&!hierarchy.empty()) {
        idx=0;
        n=0;
        vector<Point> approx;
        for (;idx>=0;idx=hierarchy[idx][0]) {
            color=colors[idx%15];
//          drawContours(smallImg,contours,idx,color,1,8,hierarchy);
            approxPolyDP(Mat(contours[idx]), approx, arcLength(Mat(contours[idx]), true)*0.005, true);//0.005为将毛边拉直的系数
            const Point* p = &approx[0];
            int m=(int)approx.size();
            polylines(smallImg, &p, &m, 1, true, color);
            circle(smallImg,Point(p[0].x,p[0].y),3,color);
            circle(smallImg,Point(p[1].x,p[1].y),2,color);
			for	(int i=2;i<m;i++) circle(smallImg,Point(p[i].x,p[i].y),1,color);
            n++;
            if (1==n) {
                maxrect=boundingRect(Mat(contours[idx]));
            } else {
                brect=boundingRect(Mat(contours[idx]));
                CvRect mr(maxrect),br(brect);
                maxrect=cvMaxRect(&mr,&br);
            }
        }
        circle(smallImg,Point(maxrect.x+maxrect.width/2,maxrect.y+maxrect.height/2),2,CV_RGB(255,0,0));
    }
    imshow("display",smallImg);
    waitKey(0);
    cvDestroyWindow("display");
    return 0;
}
加载更多回复(2)

19,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧