find number of 1s in a binary cv::mat image
C++
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <features2d.hpp>
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
//load image
Mat img = imread("kayu.jpg", CV_LOAD_IMAGE_COLOR);
if(img.empty())
return -1;
//namedWindow( "kayu", CV_WINDOW_AUTOSIZE );
imshow("kayu", img);
//convert to b/w
Mat bw;
cvtColor(img, bw, CV_BGR2GRAY);
imshow("bw1", bw);
threshold(bw, bw, 40, 255, CV_THRESH_BINARY);
imshow("bw", bw);
//distance transform & normalisasi
Mat dist;
distanceTransform(bw, dist, CV_DIST_L2, 3);
normalize(dist, dist, 0, 2., NORM_MINMAX);
imshow("dist", dist);
//threshold to draw line
threshold(dist, dist, .5, 1., CV_THRESH_BINARY);
imshow("dist2", dist);
//dist = bw;
//dilasi
Mat dilation, erotion, element;
int dilation_type = MORPH_ELLIPSE;
int dilation_size = 17;
element = getStructuringElement(dilation_type, Size(2*dilation_size + 1, 2*dilation_size+1), Point(dilation_size, dilation_size ));
erode(dist, erotion, element);
int erotionCount = 0;
for(int i=0; i<erotionCount; i++){
erode(erotion, erotion, element);
}
imshow("erotion", erotion);
dilate(erotion, dilation, element);
imshow("dilation", dilation);
waitKey(0);
return 0;
}
Also in C++:
- Title
- set in c++
- Category
- C++
- Title
- mysqli connect
- Category
- C++
- Title
- how to sort an array according to another array c++
- Category
- C++
- Title
- strchr function in c++
- Category
- C++
- Title
- type id c++
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- what is time complexity of insertion sort
- Category
- C++
- Title
- c++ base 10 to base 2
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- find in set of pairs using first value cpp
- Category
- C++
- Title
- binary tree deletion
- Category
- C++
- Title
- c++ passing two dimensional array to function
- Category
- C++
- Title
- c++ max of array
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- cpp pi from acos
- Category
- C++
- Title
- c++ menu selection with arrow keys
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- how to convert a string to a double c++
- Category
- C++
- Title
- hohw toparse a string in c++
- Category
- C++
- Title
- passing array to function in c++
- Category
- C++
- Title
- tellg and seekg c++
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- c++ remove text file
- Category
- C++
- Title
- : error: ‘cont’ cannot be used as a function return (cont(cont-1))/2;
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- primitive and non primitive data types in c++
- Category
- C++
- Title
- convert integer to string c++
- Category
- C++
- Title
- c++ do while loop
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- c++ code 2d block
- Category
- C++
- Title
- filling 2d array with 0 c++
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- longest common subsequence
- Category
- C++
- Title
- switch case sinax c++
- Category
- C++
- Title
- calling by reference and pointers c++
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- worker class c++
- Category
- C++
- Title
- findung the mode in c++
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- set lower bound c++
- Category
- C++
- Title
- statement that causes a function to end in c++
- Category
- C++
- Title
- c++ server service ros
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- inverser les éléments d'un tableau manuellement en c++
- Category
- C++
- Title
- dfs in c++
- Category
- C++
- Title
- how to create object in c++
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- how to run a c++ program in the background
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- free or delete in c++
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- Merge k sorted linked lists and return it as one sorted list.
- Category
- C++
- Title
- length of string in c++
- Category
- C++
- Title
- switch statement c++
- Category
- C++
- Title
- never gonna give you up lyrics
- Category
- C++
- Title
- hashset in c++
- Category
- C++
- Title
- error: invalid conversion from 'Node*' to 'int'
- Category
- C++
- Title
- c++ find object in vector by attribute
- Category
- C++
- Title
- linear search in c++
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- double to string c++
- Category
- C++
- Title
- C++ string format ctime
- Category
- C++
- Title
- how to pass an object by reference in c++
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- time function c++
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- C++ pointer arithmetic
- Category
- C++
- Title
- C++ user input
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- programa para saber si un numero es primo
- Category
- C++
- Title
- c++ push multiple elements to vector
- Category
- C++
- Title
- set of vectors c++
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- elseif c++
- Category
- C++
- Title
- how to convert qt string to string
- Category
- C++
- Title
- how to check datatype of a variable in c++
- Category
- C++
- Title
- kruskal's algorithm c++ hackerearth
- Category
- C++
- Title
- number of islands leetcode code
- Category
- C++
- Title
- expected unqualified-id before 'if'
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- c++ excel cell blank cells
- Category
- C++
- Title
- create a dictionary cpp
- Category
- C++
- Title
- memset
- Category
- C++
- Title
- cout value c++
- Category
- C++
- Title
- c++ string to int
- Category
- C++
- Title
- stl sort in c++
- Category
- C++
- Title
- how to find the index of an element in a vector c++
- Category
- C++
- Title
- case label in c++
- Category
- C++
- Title
- split 2d array into chunks in c++
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- string to number in c++
- Category
- C++