opencv——检测四边形的四个角点

#include "stdio.h"  
#include "cv.h"  
#include "highgui.h"  
#include "Math.h"
#define max_corners 4

#define C CV_PI /3
int Otsu(IplImage* src);

int main(int argc, char*argv[])
{
    IplImage* img = cvLoadImage("C:\\Users\\aoe\\Desktop\\xiangmu10\\fffffffff.jpg", 0);
    cvNamedWindow("img", 1);
    cvShowImage("img", img);
    IplImage* dst = cvCreateImage(cvGetSize(img), 8, 1);
    int threshold = Otsu(img);//最大类间方差阈值分割
    printf("threshold = %d\n", threshold);
    cvThreshold(img, dst, threshold, 255, CV_THRESH_BINARY);

    cvNamedWindow("dst", 1);
    cvShowImage("dst", dst);
    CvRect roi = cvRect(30, 30,120,120);//去除复杂背景

    IplImage* img1 = cvCreateImage(cvGetSize(dst), dst->depth, dst->nChannels);
    for (int y = 0; y < img1->height; y++)
    {
        for (int x = 0; x < img1->width; x++)
        {
            CvScalar cs = (255);
            cvSet2D(img1, y, x, cs);
        }
    }
    CvRect roi1 = cvRect(30, 30, 120, 120);
    cvNamedWindow("img1");
    cvShowImage("img1", img1);

    cvSetImageROI(dst, roi);
    cvSetImageROI(img1, roi1);
    cvCopy(dst, img1);
    cvResetImageROI(dst);
    cvResetImageROI(img1);

    cvNamedWindow("result", 1);
    cvShowImage("result", img1);

    IplImage*edge = cvCreateImage(cvGetSize(img1), 8, 1);//canny边缘检测
    int edgeThresh = 1;
    cvCanny(img1, edge, edgeThresh, edgeThresh * 3, 3);

    cvNamedWindow("canny", 1);
    cvShowImage("canny", edge);
    int count = 0;
    for (int yy = 0; yy < edge->height; yy++)//统计边缘图像中共有多少个黑色像素点
    {
        for (int xx = 0; xx < edge->width; xx++)
        {
            //CvScalar ss = (255);
            double ds = cvGet2D(edge, yy, xx).val[0];
            if (ds == 0)
                count++;
        }
    }
    int dianshu_threshold = (176*144-count)/ 
  • 5
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值