当前位置:网站首页>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;
}
边栏推荐
- Leetcode22 summary of types of questions brushing in 2002 (XII) and collection search
- Using transformers of hugging face to realize text classification
- ROS learning notes (5) -- Exploration of customized messages
- 2020-10-20
- Batch modify file name
- Detailed explanation of SOC multi-core startup process
- Relationship extraction -- casrel
- Time functions supported in optee
- Steps for ROS to introduce opencv (for cmakelist)
- And are two numbers of S
猜你喜欢

Design of reverse five times voltage amplifier circuit

Esp8266wifi module tutorial: punctual atom atk-esp8266 for network communication, single chip microcomputer and computer, single chip microcomputer and mobile phone to send data

See which processes occupy specific ports and shut down

Idea auto Guide

利用无线技术实现分散传感器信号远程集中控制

鲸会务一站式智能会议系统帮助主办方实现数字化会议管理

(5) Matrix key

Implementation of ffmpeg audio and video player

Transformers loading Roberta to implement sequence annotation task

2020-10-29
随机推荐
Undefined symbols for architecture i386与第三方编译的静态库有关
golang json unsupported value: NaN 处理
2020-10-20
鲸会务一站式智能会议系统帮助主办方实现数字化会议管理
Undefined symbols for architecture i386 is related to third-party compiled static libraries
Two ways to realize time format printing
多台三菱PLC如何实现无线以太网高速通讯?
Cause analysis of serial communication overshoot and method of termination
CodeBlocks integrated Objective-C development
RecyclerView Item 根据 x,y 坐标得到当前position(位置)
SQL learning experience (II): question brushing record
Teach you a few tricks: 30 "overbearing" warm words to coax girls, don't look regret!
MPC learning notes (I): push MPC formula manually
Remote centralized control of distributed sensor signals using wireless technology
Is it safe to open an account in flush,
Time functions supported in optee
optee中的timer代码导读
How to correctly PIP install pyscipopt
(5) Matrix key
利用无线技术实现分散传感器信号远程集中控制