代碼如下:
#include <opencv2/opencv.hpp>
CvMat* g_pMatContour = NULL;
static void process(...)
{
if (g_pMatContour == NULL)
{
float points[] ={470,240, 1670,168, 1846,688, 714,928};
int nContourNum = 4;
g_pMatContour = cvCreateMat(1, nContourNum, CV_32FC2);
for (int i=0; i<nContourNum; i++)
{
CvScalar vertex = cvScalar(points[i*2], points[i*2+1]);
cvSet1D(pMatContour, i, vertex);
}
}
CvPoint2D32f ptTest;
//center point
ptTest.x = pClip->left + pClip->width /2;
ptTest.y = pClip->top + pClip->height/2;
double jl = cvPointPolygonTest(g_pMatContour, ptTest, 1);
//jl > 0表示在内部。jl<0表示在外部。jl=0表示在多邊形上。
if (jl > 0)
{
//WARNING MESSAGE
}