 |
OpenCV
3.2.0
Open Source Computer Vision
|
.2.0+dfsg_doc_tutorials_imgproc_shapedescriptors_point_polygon_test_point_polygon_test
Goal
In this tutorial you will learn how to:
Theory
Code
This tutorial code's is shown lines below. You can also download it from here
#include <iostream>
using namespace std;
int main( void )
{
const int r = 100;
vector<Point2f> vert(6);
vert[0] =
Point( 3*r/2,
static_cast<int>(1.34*r) );
vert[1] =
Point( 1*r, 2*r );
vert[2] =
Point( 3*r/2,
static_cast<int>(2.866*r) );
vert[3] =
Point( 5*r/2,
static_cast<int>(2.866*r) );
vert[4] =
Point( 3*r, 2*r );
vert[5] =
Point( 5*r/2,
static_cast<int>(1.34*r) );
for( int j = 0; j < 6; j++ )
{
line( src, vert[j], vert[(j+1)%6],
Scalar( 255 ), 3, 8 ); }
vector<vector<Point> > contours; vector<Vec4i> hierarchy;
for(
int j = 0; j < src.
rows; j++ )
{
for(
int i = 0;
i < src.
cols;
i++ )
}
double minVal; double maxVal;
minVal =
abs(minVal); maxVal =
abs(maxVal);
for(
int j = 0; j < src.
rows; j++ )
{
for(
int i = 0;
i < src.
cols;
i++ )
{
if( raw_dist.at<
float>(j,
i) < 0 )
{ drawing.
at<
Vec3b>(j,
i)[0] = (
uchar)(255 -
abs(raw_dist.at<
float>(j,
i))*255/minVal); }
else if( raw_dist.at<
float>(j,
i) > 0 )
{ drawing.
at<
Vec3b>(j,
i)[2] = (
uchar)(255 - raw_dist.at<
float>(j,
i)*255/maxVal); }
else
}
}
const char* source_window = "Source";
imshow(
"Distance", drawing );
return(0);
}
Explanation
Result
Here it is:
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
Definition: mat.hpp:1959
static MatExpr zeros(int rows, int cols, int type)
Returns a zero array of the specified size and type.
_Tp & at(int i0=0)
Returns a reference to the specified array element.
Point_< float > Point2f
Definition: types.hpp:181
int waitKey(int delay=0)
Waits for a pressed key.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
Size2i Size
Definition: types.hpp:315
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a line segment connecting two points.
Template class for short numerical vectors, a partial case of Matx.
Definition: matx.hpp:306
int cols
Definition: mat.hpp:1959
#define CV_8UC3
Definition: interface.h:84
MatSize size
Definition: mat.hpp:1978
static uchar abs(uchar a)
Definition: cvstd.hpp:70
unsigned char uchar
Definition: interface.h:47
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
void minMaxLoc(InputArray src, double *minVal, double *maxVal=0, Point *minLoc=0, Point *maxLoc=0, InputArray mask=noArray())
Finds the global minimum and maximum in an array.
Scalar_< double > Scalar
Definition: types.hpp:606
Mat clone() const
Creates a full copy of the array and the underlying data.
Point2i Point
Definition: types.hpp:183
n-dimensional dense array class
Definition: mat.hpp:741
for i
Definition: modelConvert.m:63
#define CV_8UC1
Definition: interface.h:82
Definition: affine.hpp:52
@ WINDOW_AUTOSIZE
the user cannot resize the window, the size is constrainted by the image displayed.
Definition: highgui.hpp:184
@ CHAIN_APPROX_SIMPLE
Definition: imgproc.hpp:448
double pointPolygonTest(InputArray contour, Point2f pt, bool measureDist)
Performs a point-in-contour test.
void findContours(InputOutputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())
Finds contours in a binary image.
@ RETR_TREE
Definition: imgproc.hpp:436
#define CV_32FC1
Definition: interface.h:112