当前位置:网站首页>Corn image segmentation count_ nanyangjx
Corn image segmentation count_ nanyangjx
2022-06-26 08:40:00 【Algorithmic Pilgrim】
Ideas :

Process image recording :

Code
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
Mat gray_src, binary, dst;
Mat src = imread("D:/gloomyfish/case4.png");
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("input image", CV_WINDOW_AUTOSIZE);
imshow("input image", src);
cvtColor(src, gray_src, COLOR_BGR2GRAY);
// Binary segmentation
threshold(gray_src, binary, 0, 255, THRESH_BINARY | THRESH_TRIANGLE);
imshow("binary image", binary);
// Morphological operation
Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
dilate(binary, binary, kernel, Point(-1, -1), 1);
imshow("dilate image", binary);
// Distance transformation
Mat dist;
bitwise_not(binary, binary);
distanceTransform(binary, dist, CV_DIST_L2, 3);
normalize(dist, dist, 0, 1.0, NORM_MINMAX);
imshow("dist image", dist);
// Thresholding binary segmentation
Mat dist_8u;
dist.convertTo(dist_8u, CV_8U);
adaptiveThreshold(dist_8u, dist_8u, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 85, 0.0);
kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
dilate(dist_8u, dist_8u, kernel, Point(-1, -1), 2);
imshow("dist-binary", dist_8u);
// Connected area count
vector<vector<Point>> contours;
findContours(dist_8u, contours, CV_RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
// draw result
Mat markers = Mat::zeros(src.size(), CV_8UC3);
RNG rng(12345);
for (size_t t = 0; t < contours.size(); t++) {
drawContours(markers, contours, static_cast<int>(t), Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)),
-1, 8, Mat());
}
printf("number of corns : %d", contours.size());
imshow("Final result", markers);
waitKey(0);
return 0;
}
边栏推荐
- Teach you a few tricks: 30 "overbearing" warm words to coax girls, don't look regret!
- STM32 project design: smart door lock PCB and source code based on stm32f1 (4 unlocking methods)
- loading view时,后面所有东西屏蔽
- Use a switch to control the lighting and extinguishing of LEP lamp
- 2020-10-29
- STM32 encountered problems using encoder module (library function version)
- Esp8266wifi module tutorial: punctual atom atk-esp8266 for network communication, single chip microcomputer and computer, single chip microcomputer and mobile phone to send data
- Software engineering - personal assignment - question review and personal summary
- Monitor iPad Keyboard Display and hide events
- Formula understanding in quadruped control
猜你喜欢

Whale conference one-stop intelligent conference system helps organizers realize digital conference management

Idea auto Guide

Leetcode22 summary of types of questions brushing in 2002 (XII) and collection search

Detailed process of generating URDF file from SW model

WBC learning notes (II): practical application of WBC control

Stanford doggo source code study

73b2d wireless charging and receiving chip scheme

Compiling owncloud client on win10

HEVC学习之码流分析

【Unity Mirror】NetworkTeam的使用
随机推荐
批量执行SQL文件
Installation of jupyter
Implementation of ffmpeg audio and video player
How to realize wireless Ethernet high-speed communication for multiple Mitsubishi PLCs?
Using transformers of hugging face to realize multi label text classification
Partial summary of 45 lectures on geek time MySQL
Zlib static library compilation
RecyclerView Item 根据 x,y 坐标得到当前position(位置)
73b2d wireless charging and receiving chip scheme
Swift code implements method calls
SOC的多核启动流程详解
在 KubeSphere 部署 Wiki 系统 wiki.js 并启用中文全文检索
Discrete device ~ diode triode
MPC learning notes (I): push MPC formula manually
OpenCV Learning notes iii
Detailed explanation of self attention & transformer
Koa_ mySQL_ Integration of TS
drf的相关知识
nn. Modulelist and nn Sequential
Relationship extraction -- casrel