当前位置:网站首页>Opencv calculation outsourcing rectangle
Opencv calculation outsourcing rectangle
2022-07-23 14:48:00 【Chaoying.】
Separate calculation Parallel to the coordinate axis Circumscribed rectangle and Minimum area The outer rectangle of
#include <opencv.hpp>
#include <iostream>
using namespace std;
void CornerSift(string ImageName,cv::Rect &boundingRec,cv::RotatedRect &minAreaRec)
{
cv::Mat ImageInput;
ImageInput = cv::imread(ImageName,cv::ImreadModes::IMREAD_COLOR);
if (ImageInput.empty())
{
cout << " The image file is empty !" << std::endl;
return;
}
cv::Mat ImageRGB/* Corner detection color */, ImageGray;
ImageInput.copyTo(ImageRGB);
cvtColor(ImageRGB, ImageGray, cv::COLOR_BGR2GRAY);
vector<cv::KeyPoint> Keypoints;
float thContrast = 0.03;// Corner contrast threshold
float thEdge = 10;// Ratio of eigenvalues . The smaller the corner, the higher the quality
cv::Ptr<cv::Feature2D> f2d = cv::SIFT::create(0, 3, thContrast, thEdge, 1.6);
f2d->detect(ImageGray, Keypoints);
int num = Keypoints.size();
// Print point coordinates
vector<cv::Point2f> kPxys;
for (int i = 0; i < num; i++)
{
cv::KeyPoint kP = Keypoints[i];
//cout << kP.pt.x << "\t" << kP.pt.y << endl;
kPxys.push_back(kP.pt);
}
// Draw feature points
cv::drawKeypoints(ImageRGB, Keypoints, ImageRGB, cv::Scalar(255, 255, 0), cv::DrawMatchesFlags::DEFAULT);
// be based on sift Feature point calculation minimum circumscribed rectangle
// Circumscribed rectangle parallel to the coordinate axis
boundingRec = cv::boundingRect(kPxys);
cv::rectangle(ImageRGB, boundingRec, cv::Scalar(255, 0, 0),2);
// Minimum area circumscribed rectangle
minAreaRec = cv::minAreaRect(kPxys);
cv::Point2f minAreaRecOPoints[4];
minAreaRec.points(minAreaRecOPoints);
for (int i = 0; i < 4; i++)
{
cv::Point2f startPoint = minAreaRecOPoints[i];
cv::Point2f endPoint;
if (i != 3)
{
endPoint = minAreaRecOPoints[i + 1];
}
else
{
endPoint = minAreaRecOPoints[0];
}
cv::line(ImageRGB, startPoint, endPoint, cv::Scalar(0, 255, 0), 2);
}
cv::imshow("2D Features", ImageRGB);
cv::waitKey(0);
cv::destroyAllWindows();
return;
}
int main()
{
cv::Rect boundingRec;
cv::RotatedRect minAreaRec;
CornerSift("t3.jpg",boundingRec,minAreaRec);
// Get information about rectangles
cv::Point2f center = minAreaRec.center;
cv::Size2f recSize = minAreaRec.size;
float recAngle = minAreaRec.angle;
cout << center << endl;
cout << recSize << endl;
cout << recAngle << endl;
return 0;
}
effect 
边栏推荐
猜你喜欢
![[can I do your first project?] Detailed introduction and Simulation Implementation of gzip](/img/92/dfef5887e2313f8025baf11c8f4379.png)
[can I do your first project?] Detailed introduction and Simulation Implementation of gzip

Qt文档阅读笔记-Audio Example解析

How can manual testing turn to automated testing? Byte 5 years of automation experience talk about

Okrk3399 Development Board reserves i2c4 to mount EEPROM

利用js自动解析执行xss

【 langage c】 devinez jeux numériques + applet d'arrêt

Yunna | how to manage the fixed assets of the company? How to manage the company's fixed assets better?

【数组&&字符串&&宏练习题】
![[array & String & Macro exercise]](/img/44/26debc1ee958277935e73a75d894d4.png)
[array & String & Macro exercise]

运维高级作业02
随机推荐
Canvas from getting started to persuading friends to give up (graphic version)
Introduction and mechanism of Aptos
Palindrome related topics
Towhee weekly model
【测试平台开发】十七、接口编辑页面实现下拉级联选择,绑定接口所属模块...
Wacom firmware update error 123, digital board driver cannot be updated
Aruba learning notes 05 configuration architecture WLAN configuration architecture
[applet automation minium] III. element positioning - use of wxss selector
第2章 基础查询与排序
JS calendar style pie chart statistics plug-in
【C语言】猜数字小游戏+关机小程序
CPU,内存,磁盘速度比较
R language practical application case: drawing part (III) - drawing of multiple combination patterns
【FLink】FLink Hash collision on user-specified ID “opt“. Most likely cause is a non-unique ID
LZ77 file compression
Qt|模仿文字浮动字母
【小程序自动化Minium】一、框架介绍和环境搭建
OpenHarmony南向学习笔记——Hi3861+HC-SR04超声波检测
優化華為雲服務器采用Key登陸
C language implements memcpy and memmove