7 #include <opencv2/opencv.hpp>
13 int main(
int,
char** argv)
24 imshow(
"Source Image", src);
30 for(
int x = 0; x < src.
rows; x++ ) {
31 for(
int y = 0; y < src.
cols; y++ ) {
41 imshow(
"Black Background Image", src);
61 Mat imgResult = sharp - imgLaplacian;
65 imgLaplacian.convertTo(imgLaplacian,
CV_8UC3);
68 imshow(
"New Sharped Image", imgResult );
78 imshow(
"Binary Image", bw);
89 imshow(
"Distance Transform Image", dist);
99 dilate(dist, dist, kernel1);
110 vector<vector<Point> > contours;
117 for (
size_t i = 0; i < contours.size(); i++)
118 drawContours(markers, contours, static_cast<int>(i), Scalar::all(static_cast<int>(i)+1), -1);
122 imshow(
"Markers", markers*10000);
136 vector<Vec3b> colors;
137 for (
size_t i = 0; i < contours.size(); i++)
150 for (
int i = 0; i < markers.
rows; i++)
152 for (
int j = 0; j < markers.
cols; j++)
155 if (index > 0 && index <= static_cast<int>(contours.size()))
156 dst.
at<
Vec3b>(
i,j) = colors[index-1];
163 imshow(
"Final Result", dst);
Vec< uchar, 3 > Vec3b
Definition: matx.hpp:358
#define CV_32SC1
Definition: cvdef.h:140
#define CV_8U
Definition: cvdef.h:101
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
Converts an image from one color space to another.
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions ...
Definition: mat.hpp:1865
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
Definition: types_c.h:121
void convertTo(OutputArray m, int rtype, double alpha=1, double beta=0) const
Converts an array to another data type with optional scaling.
uchar * data
pointer to the data
Definition: mat.hpp:1867
void distanceTransform(InputArray src, OutputArray dst, OutputArray labels, int distanceType, int maskSize, int labelType=DIST_LABEL_CCOMP)
Calculates the distance to the closest zero pixel for each pixel of the source image.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
#define CV_RGB(r, g, b)
Definition: imgproc_c.h:985
Definition: types_c.h:458
#define CV_8UC1
Definition: cvdef.h:116
Definition: types_c.h:446
Definition: types_c.h:571
Definition: gr_skig.hpp:77
void drawContours(InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar &color, int thickness=1, int lineType=LINE_8, InputArray hierarchy=noArray(), int maxLevel=INT_MAX, Point offset=Point())
Draws contours outlines or filled contours.
void filter2D(InputArray src, OutputArray dst, int ddepth, InputArray kernel, Point anchor=Point(-1,-1), double delta=0, int borderType=BORDER_DEFAULT)
Convolves an image with the kernel.
void watershed(InputArray image, InputOutputArray markers)
Performs a marker-based image segmentation using the watershed algorithm.
Template class for short numerical vectors, a partial case of Matx.
Definition: matx.hpp:300
void dilate(InputArray src, OutputArray dst, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar &borderValue=morphologyDefaultBorderValue())
Dilates an image by using a specific structuring element.
int cols
Definition: mat.hpp:1865
MatSize size
Definition: mat.hpp:1882
RNG & theRNG()
Returns the default random number generator.
unsigned char uchar
Definition: defs.h:284
static Vec< _Tp, cn > normalize(const Vec< _Tp, cn > &v)
int uniform(int a, int b)
returns uniformly distributed integer random number from [a,b) range
void bitwise_not(InputArray src, OutputArray dst, InputArray mask=noArray())
Inverts every bit of an array.
Definition: types_c.h:559
for i
Definition: modelConvert.m:63
#define CV_8UC3
Definition: cvdef.h:118
double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
Applies a fixed-level threshold to each array element.
Definition: gr_skig.hpp:62
flag
Definition: base.hpp:176
void findContours(InputOutputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())
Finds contours in a binary image.
#define CV_32F
Definition: cvdef.h:106
int main(int argc, const char *argv[])
Definition: facerec_demo.cpp:67
n-dimensional dense array class
Definition: mat.hpp:726
_Tp & at(int i0=0)
Returns a reference to the specified array element.
Definition: types_c.h:577
Point2i Point
Definition: types.hpp:181
int waitKey(int delay=0)
Waits for a pressed key.