forked from spmallick/learnopencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b311b6
commit 8fc07d9
Showing
5 changed files
with
76 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## Center of Blob using Python and C++ | ||
|
||
To run the code to find center of a single blob, run the following commands:- | ||
|
||
For python:- | ||
|
||
`python3 single_blob.py --ipimage image_name` | ||
|
||
|
||
For C++:- | ||
|
||
1. ``g++ single_blob.cpp `pkg-config opencv --cflags --libs` -o output`` | ||
|
||
2. `./output image_name` | ||
|
||
To run the code to find center of multiple blobs, run the following commands:- | ||
|
||
For python:- | ||
|
||
`python3 center_of_multiple_blob.py --ipimage image_name` | ||
|
||
For C++:- | ||
|
||
1. ``g++ center_of_multiple_blob.cpp `pkg-config opencv --cflags --libs` -o output`` | ||
|
||
2. `./output image_name` | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
// declare Mat variables, thr, gray and src | ||
Mat thr, gray, src; | ||
|
||
// convert image to grayscale | ||
cvtColor( src, gray, COLOR_BGR2GRAY ); | ||
|
||
// convert grayscale to binary image | ||
threshold( gray, thr, 100,255,THRESH_BINARY ); | ||
|
||
// find moments of the image | ||
Moments m = moments(thr,true); | ||
Point p(m.m10/m.m00, m.m01/m.m00); | ||
|
||
// coordinates of centroid | ||
cout<< Mat(p)<< endl; | ||
|
||
// show the image with a point mark at the centroid | ||
circle(src, p, 5, Scalar(128,0,0), -1); | ||
imshow("Image with center",src); | ||
waitKey(0); | ||
#include "opencv2/highgui/highgui.hpp" | ||
#include "opencv2/imgproc/imgproc.hpp" | ||
#include <iostream> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
using namespace cv; | ||
using namespace std; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
// Declare Mat type images | ||
Mat src, gray,thr; | ||
|
||
//Load source image, convert it to gray | ||
src = imread(argv[1], 1 ); | ||
|
||
// convert image to grayscale | ||
cvtColor( src, gray, COLOR_BGR2GRAY ); | ||
|
||
// convert grayscale to binary image | ||
threshold( gray, thr, 100,255,THRESH_BINARY ); | ||
|
||
// find moments of the image | ||
Moments m = moments(thr,true); | ||
Point p(m.m10/m.m00, m.m01/m.m00); | ||
|
||
// coordinates of centroid | ||
cout<< Mat(p)<< endl; | ||
|
||
// show the image with a point mark at the centroid | ||
circle(src, p, 5, Scalar(128,0,0), -1); | ||
imshow("Image with center",src); | ||
waitKey(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters