当前位置:网站首页>Opencv learning log 27 -- chip positioning
Opencv learning log 27 -- chip positioning
2022-07-06 16:07:00 【@Spring sauce】
Preface
This article focuses on opencv Application of chip positioning in image processing .
One 、 Chip positioning
// Chip positioning
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
cv::Mat dst;
cv::Mat dstbin;
cv::Mat dsttemp;
cv::Mat resMat;
cv::Mat Matstate;
cv::Mat center;
cv::Mat src = imread("C://Users//john//Desktop//1.jpg");
cv::Mat srcgray = imread("C://Users//john//Desktop//1.jpg", 0);
threshold(srcgray, dstbin, 100, 255, THRESH_OTSU); // Dajin law
cv::imshow("dstbin", dstbin);
src.copyTo(dst);
//bitwise_not(dstbin, dsttemp);
vector<vector<Point>> contours;
vector<Vec4i> hirearchy;
findContours(dstbin, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
int num = contours.size();
//cout << num << endl;
Point2f rect[4];
for (int i = 0; i < num; i++)
{
RotatedRect rbox = minAreaRect(contours[i]);
///cout << rbox << endl;
int area = contourArea(contours[i]);// Calculate the contour area
rbox.points(rect); // Copy the four ends of the smallest circumscribed rectangle to rect Array
if (fabs(rbox.size.width * 1.0 / rbox.size.height - 1) < 0.2&&area>=100)
{
drawContours(dst, contours, i, Scalar(255, 0, 0), -1, 8);
for (int j = 0; j<4; j++)
{
line(dst, rect[j], rect[(j + 1) % 4], Scalar(255, 255, 255), 2, 8); // Draw the smallest outer edge of each rectangle
}
}
}
cv::imshow("dsttemp", dstbin);
cv::imshow("dst", dst);
waitKey(0);
}
summary
1. The code can run directly , If you don't understand, please leave a message .
2. Missing material pictures , Follow up, thank you .
边栏推荐
- The most complete programming language online API document
- Research Report of cylindrical grinder industry - market status analysis and development prospect forecast
- E. Breaking the Wall
- 信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
- B - Code Party (girls' competition)
- Penetration test (3) -- Metasploit framework (MSF)
- 渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
- Path problem before dynamic planning
- HDU-6025-Coprime Sequence(女生赛)
- Gartner: five suggestions on best practices for zero trust network access
猜你喜欢

Penetration test (8) -- official document of burp Suite Pro

Penetration test (1) -- necessary tools, navigation

C language learning notes

Pyside6 signal, slot

信息安全-威胁检测-NAT日志接入威胁检测平台详细设计

STM32 learning record: LED light flashes (register version)

渗透测试 ( 8 ) --- Burp Suite Pro 官方文档

1010 things that college students majoring in it must do before graduation

Nodejs+vue online fresh flower shop sales information system express+mysql
frida hook so层、protobuf 数据解析
随机推荐
信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
【练习-8】(Uva 246)10-20-30==模拟
Write web games in C language
Find 3-friendly Integers
[exercise -11] 4 values why sum is 0 (and 4 values of 0)
STM32 learning record: LED light flashes (register version)
【高老师UML软件建模基础】20级云班课习题答案合集
Nodejs+vue网上鲜花店销售信息系统express+mysql
CEP used by Flink
Determine the Photo Position
Opencv learning log 32 edge extraction
If you want to apply for a programmer, your resume should be written like this [essence summary]
F - birthday cake (Shandong race)
Nodejs+vue online fresh flower shop sales information system express+mysql
nodejs爬虫
Alice and Bob (2021牛客暑期多校训练营1)
渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
【练习-10】 Unread Messages(未读消息)
7-1 懂的都懂 (20 分)
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)