当前位置:网站首页>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 .
边栏推荐
- Truck History
- Opencv learning log 30 -- histogram equalization
- China's earthwork tire market trend report, technical dynamic innovation and market forecast
- X-forwarded-for details, how to get the client IP
- C language learning notes
- New to redis
- 【练习-6】(Uva 725)Division(除法)== 暴力
- B - 代码派对(女生赛)
- Information security - Analysis of security orchestration automation and response (soar) technology
- Research Report on market supply and demand and strategy of China's earth drilling industry
猜你喜欢

Basic Q & A of introductory C language

Nodejs+vue网上鲜花店销售信息系统express+mysql

Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools

b站 實時彈幕和曆史彈幕 Protobuf 格式解析

信息安全-史诗级漏洞Log4j的漏洞机理和防范措施

STM32 how to use stlink download program: light LED running light (Library version)

基于web的照片数码冲印网站

Gartner:关于零信任网络访问最佳实践的五个建议

差分(一维,二维,三维) 蓝桥杯三体攻击

Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
随机推荐
Penetration test (3) -- Metasploit framework (MSF)
X-forwarded-for details, how to get the client IP
区间和------离散化
Gartner:关于零信任网络访问最佳实践的五个建议
Auto.js入门
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
[exercise 4-1] cake distribution
Analysis of protobuf format of real-time barrage and historical barrage at station B
Penetration test (8) -- official document of burp Suite Pro
【练习-1】(Uva 673) Parentheses Balance/平衡的括号 (栈stack)
The concept of C language array
Find 3-friendly Integers
【练习-8】(Uva 246)10-20-30==模拟
Opencv learning log 14 - count the number of coins in the picture (regardless of overlap)
D - function (HDU - 6546) girls' competition
Gartner: five suggestions on best practices for zero trust network access
D - Function(HDU - 6546)女生赛
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
Opencv learning log 30 -- histogram equalization
Penetration test (7) -- vulnerability scanning tool Nessus