• 2个多边形的关系判断和相交面积计算



    #include "stdafx.h"
    #include <cv.h>
    #include <highgui.h>

    IplImage *Image1;

    CvPoint PointArray1[6];
    CvPoint PointArray2[4];
    CvScalar Color;
    int PolyVertexNumber;
    int Shift;
    int main()
    {
    CvSize ImageSize1 = cvSize(1000,700);
    Image1 = cvCreateImage(ImageSize1, IPL_DEPTH_8U, 3);
    IplImage* Image2 = cvCreateImage(ImageSize1, IPL_DEPTH_8U, 3);
    IplImage* Image3 = cvCreateImage(ImageSize1, IPL_DEPTH_8U, 3);
    IplImage* Image4 = cvCreateImage(ImageSize1, IPL_DEPTH_8U, 1);
    PointArray1[0]=cvPoint(200,200);
    PointArray1[1]=cvPoint(400,150);
    PointArray1[2]=cvPoint(650,230);
    PointArray1[3]=cvPoint(800,300);
    PointArray1[4]=cvPoint(900,550);
    PointArray1[5]=cvPoint(100,500);

    PointArray2[0]=cvPoint(20,20);
    PointArray2[1]=cvPoint(30,20);
    PointArray2[2]=cvPoint(30,30);
    PointArray2[3]=cvPoint(20,30);

    CvScalar Color=CV_RGB(0,255,0);
    PolyVertexNumber=6;
    Shift=0;

    cvFillConvexPoly(Image1,PointArray1,PolyVertexNumber,Color,CV_AA,Shift);


    Color=CV_RGB(0,0,255,);
    cvFillConvexPoly(Image2,PointArray2,4,Color,CV_AA,Shift);

    cvAbsDiff(Image1,Image2,Image3);

    cvThreshold(Image3,Image3,250,255,CV_THRESH_BINARY );
    //
    cvCvtColor(Image3,Image4,CV_BGR2GRAY);
    cvThreshold(Image4,Image4,50,255,CV_THRESH_BINARY );
    CvMemStorage *storage=cvCreateMemStorage(0);
    CvSeq *contours=0;

    int rs = cvFindContours(Image4,storage,&contours,sizeof(CvContour),
    CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    double rr=0;
    if (rs==1)
    {
    rr= cvContourArea(contours);
    }

    cvNamedWindow("FillConvexPoly",0);
    cvShowImage("FillConvexPoly",Image1);
    cvShowImage("FillConvexPoly2",Image2);
    cvShowImage("FillConvexPoly3",Image3);
    cvWaitKey(0);
    //cvSaveImage("poly.jpg",Image1);
    cvReleaseImage(&Image1);
    return 0;
    }

  • 相关阅读:
    扩散模型+文本生成
    期末总结
    查看笔记本电池损耗
    Qt数据可视化(散点图、折线图、柱状图、盒须图、饼状图、雷达图)开发实例
    24点游戏题库算法分析
    Qt项目开发实例 (含源码)
    Knowledge base for Interview
    System integration
    powerdesigner的使用
    VC++60MFC框架学习增加拖拽
  • 原文地址:https://www.cnblogs.com/ahuo/p/3055684.html
Copyright © 2020-2023  润新知