当前位置:网站首页>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 .
边栏推荐
猜你喜欢

【练习-7】Crossword Answers

Determine the Photo Position

Determine the Photo Position

【练习-5】(Uva 839)Not so Mobile(天平)

Essai de pénétration (1) - - outils nécessaires, navigation

渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具

Penetration test (7) -- vulnerability scanning tool Nessus

Borg maze (bfs+ minimum spanning tree) (problem solving report)
快速转 TypeScript 指南

Penetration test (3) -- Metasploit framework (MSF)
随机推荐
Web based photo digital printing website
China's peripheral catheter market trend report, technological innovation and market forecast
Penetration test (8) -- official document of burp Suite Pro
【练习-6】(Uva 725)Division(除法)== 暴力
渗透测试 ( 8 ) --- Burp Suite Pro 官方文档
信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
Information security - Analysis of security orchestration automation and response (soar) technology
B - Code Party (girls' competition)
[exercise-3] (UVA 442) matrix chain multiplication
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
Understand what is a programming language in a popular way
SSM框架常用配置文件
信息安全-威胁检测引擎-常见规则引擎底座性能比较
b站 实时弹幕和历史弹幕 Protobuf 格式解析
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
B - 代码派对(女生赛)
【练习-5】(Uva 839)Not so Mobile(天平)
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
渗透测试 ( 4 ) --- Meterpreter 命令详解
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures