当前位置:网站首页>Line detection_ nanyangjx
Line detection_ nanyangjx
2022-06-26 08:40:00 【Algorithmic Pilgrim】
principle :

Code :
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
using namespace cv;
using namespace std;
int max_count = 255;
int threshold_value = 100;
const char* output_lines = "Hough Lines";
Mat src, roiImage, dst;
void detectLines(int, void*);
void morhpologyLines(int, void*);
int main(int argc, char** argv) {
src = imread("D:/gloomyfish/case2.png", IMREAD_GRAYSCALE);
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("input image", CV_WINDOW_AUTOSIZE);
imshow("input image", src);
namedWindow(output_lines, CV_WINDOW_AUTOSIZE);
Rect roi = Rect(10, 10, src.cols - 20, src.rows - 20);
roiImage = src(roi);
imshow("ROI image", roiImage);
// createTrackbar("threshold:", output_lines, &threshold_value, max_count, detectLines);
// detectLines(0, 0);
morhpologyLines(0, 0);
waitKey(0);
return 0;
}
void detectLines(int, void*) {
Canny(roiImage, dst, threshold_value, threshold_value * 2, 3, false);
//threshold(roiImage, dst, 0, 255, THRESH_BINARY | THRESH_OTSU);
vector<Vec4i> lines;
HoughLinesP(dst, lines, 1, CV_PI / 180.0, 30, 30.0, 0);
cvtColor(dst, dst, COLOR_GRAY2BGR);
for (size_t t = 0; t < lines.size(); t++) {
Vec4i ln = lines[t];
line(dst, Point(ln[0], ln[1]), Point(ln[2], ln[3]), Scalar(0, 0, 255), 2, 8, 0);
}
imshow(output_lines, dst);
}
void morhpologyLines(int, void*) {
// binary image
Mat binaryImage, morhpImage;
threshold(roiImage, binaryImage, 0, 255, THRESH_BINARY_INV | THRESH_OTSU);
imshow("binary", binaryImage);
// morphology operation
Mat kernel = getStructuringElement(MORPH_RECT, Size(20, 1), Point(-1, -1));
morphologyEx(binaryImage, morhpImage, MORPH_OPEN, kernel, Point(-1, -1));
imshow("morphology result", morhpImage);
// dilate image
kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
dilate(morhpImage, morhpImage, kernel);
imshow("morphology lines", morhpImage);
// hough lines
vector<Vec4i> lines;
HoughLinesP(morhpImage, lines, 1, CV_PI / 180.0, 30, 20.0, 0);
Mat resultImage = roiImage.clone();
cvtColor(resultImage, resultImage, COLOR_GRAY2BGR);
for (size_t t = 0; t < lines.size(); t++) {
Vec4i ln = lines[t];
line(resultImage, Point(ln[0], ln[1]), Point(ln[2], ln[3]), Scalar(0, 0, 255), 2, 8, 0);
}
imshow(output_lines, resultImage);
return;
}
边栏推荐
- WBC learning notes (II): practical application of WBC control
- Calculation of decoupling capacitance
- What are the conditions for Mitsubishi PLC to realize Ethernet wireless communication?
- Fabrication of modulation and demodulation circuit
- Compiling owncloud client on win10
- [unity mirror] use of networkteam
- Golang JSON unsupported value: Nan processing
- 教你几招:30句哄女孩的“霸道”温馨话,不看后悔!
- 鲸会务一站式智能会议系统帮助主办方实现数字化会议管理
- Relevant knowledge of DRF
猜你喜欢

Analysis of internal circuit of operational amplifier

51 single chip microcomputer project design: schematic diagram of timed pet feeding system (LCD 1602, timed alarm clock, key timing) Protues, KEIL, DXP

XXL job configuration alarm email notification

Intra class data member initialization of static const and static constexpr

Using MySQL and Qt5 to develop takeout management system (I): environment configuration

SQL learning experience (II): question brushing record

How to realize wireless Ethernet high-speed communication for multiple Mitsubishi PLCs?

Relationship extraction --r-bert

Fabrication of modulation and demodulation circuit
![[postgraduate entrance examination] group planning: interrupted](/img/ec/1f3dc0ac22e3a80d721303864d2337.jpg)
[postgraduate entrance examination] group planning: interrupted
随机推荐
Relationship extraction -- casrel
Interpretation of x-vlm multimodal model
Relevant knowledge of DRF
批量执行SQL文件
Text to SQL model ----irnet
Idea auto Guide
Batch execute SQL file
Convex optimization of quadruped
STM32 project design: smart door lock PCB and source code based on stm32f1 (4 unlocking methods)
ROS learning notes (6) -- function package encapsulated into Library and called
XXL job configuration alarm email notification
Exploration of webots and ROS joint simulation (II): model import
Can the encrypted JS code and variable name be cracked and restored?
Tokenizer description in Bert
How to correctly PIP install pyscipopt
Idea uses regular expressions for global substitution
Detailed explanation of SOC multi-core startup process
Using MySQL and Qt5 to develop takeout management system (I): environment configuration
Two ways to realize time format printing
Matlab function foundation (directly abandon version)