updated code

This commit is contained in:
Krutika Bapat committed 2018-07-23 20:22:35 +05:30
1 parent 7b311b62a4
commit 8fc07d9a2d
5 files changed
+76 -21

No files matched your search

+27
View File
@@ -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`
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

+35 -20
View File
@@ -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);
}
+14 -1
View File
@@ -1,3 +1,16 @@
import cv2
import numpy as np
import argparse
# create object to pass argument
arg_parse = argparse.ArgumentParser()
arg_parse.add_argument("-i", "--ipimage", required=True,
help="input image path")
args = vars(arg_parse.parse_args())
# read image through command line
img = cv2.imread(args["ipimage"])
# convert image to grayscale image
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
@@ -17,4 +30,4 @@ cv2.putText(img, "centroid", (cX - 25, cY - 25),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (
# display the image
cv2.imshow("Image", img)
cv2.waitKey(0)
cv2.waitKey(0)