国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

鄭州市熱點(diǎn)新聞優(yōu)化游戲卡頓的軟件

鄭州市熱點(diǎn)新聞,優(yōu)化游戲卡頓的軟件,網(wǎng)站開發(fā)文獻(xiàn)綜述范文,工信部網(wǎng)站備案網(wǎng)址文章目錄 一、輪廓findContours發(fā)現(xiàn)輪廓drawContours繪制輪廓代碼 二.幾何及特性概括——凸包(Convex Hull)凸包概念凸包掃描算法介紹——Graham掃描算法 相關(guān)API介紹程序示例輪廓集合及特性性概括——輪廓周圍繪制矩形框和圓形相關(guān)理論介紹輪廓周圍繪制矩形 -API繪制步驟程序?qū)崱?article class="baidu_pl">

文章目錄

  • 一、輪廓
    • findContours發(fā)現(xiàn)輪廓
    • drawContours繪制輪廓
    • 代碼
  • 二.幾何及特性概括——凸包(Convex Hull)
    • 凸包概念
    • 凸包掃描算法介紹——Graham掃描算法
  • 相關(guān)API介紹
  • 程序示例
  • 輪廓集合及特性性概括——輪廓周圍繪制矩形框和圓形
    • 相關(guān)理論介紹
    • 輪廓周圍繪制矩形 -API
    • 繪制步驟
    • 程序?qū)嵗?/li>
  • 四.圖像矩(Image Moments)
    • 1、相關(guān)理論
    • 2、API介紹
    • 計(jì)算輪廓面積cv::contourArea
    • .計(jì)算輪廓長(zhǎng)度cv::arcLength
    • 例程
  • 五、多邊形測(cè)試
  • 1.相關(guān)理論
    • 2.相關(guān)API介紹
    • 程序示例

一、輪廓

輪廓發(fā)現(xiàn)是基于圖像邊緣提取的基礎(chǔ)尋找對(duì)象輪廓的方法。 所以邊緣提取的閾值選定會(huì)影響最終輪廓發(fā)現(xiàn)結(jié)果

輪廓查找步驟:

  • 輸入圖像轉(zhuǎn)為灰度圖像cvtColor
  • 使用Canny進(jìn)行邊緣提取或者threshold閾值操作,得到二值圖像
  • 使用findContours尋找輪廓
  • 使用drawContours繪制輪廓

findContours發(fā)現(xiàn)輪廓

在二值圖像上發(fā)現(xiàn)輪廓使用

cv::findContours(
InputOutputArray binImg,     輸入圖像,非0的像素被看成1,0的像素值保持不變,8-bit
OutputArrayOfArrays contours,  全部發(fā)現(xiàn)的輪廓對(duì)象
OutputArray, hierachy      圖該的拓?fù)浣Y(jié)構(gòu) std::vector<cv::Vec4i>,可選,該輪廓發(fā)現(xiàn)算法正是基于圖像拓?fù)浣Y(jié)構(gòu)實(shí)現(xiàn)。它的元素與輪廓的數(shù)量一樣多。對(duì)于每個(gè)第 i 個(gè)輪廓輪廓[i],元素hierarchy[i][0]、hierarchy[i][1]
int mode,            輪廓返回的模式
int method,            發(fā)現(xiàn)方法
Point offset=Point()       輪廓像素的位移,默認(rèn)(0, 0)沒有位移
)

drawContours繪制輪廓

在二值圖像上發(fā)現(xiàn)輪廓cv::findContours之后對(duì)發(fā)現(xiàn)的輪廓數(shù)據(jù)進(jìn)行繪制顯示

drawContours(
InputOutputArray binImg,      輸出圖像
OutputArrayOfArrays contours,    全部發(fā)現(xiàn)的輪廓對(duì)象
Int contourIdx            輪廓索引號(hào)
const Scalar & color,        繪制顏色
int thickness,/           繪制線寬
int lineType ,             線的類型LINE_8
InputArray hierarchy,        拓?fù)浣Y(jié)構(gòu)圖
int maxlevel,           最大層數(shù), 0只繪制當(dāng)前的,1表示繪制繪制當(dāng)前及其內(nèi)嵌的輪廓
Point offset=Point()        輪廓位移,可選

代碼

//輪廓發(fā)現(xiàn):通過cv::fingContoursAPI查找輪廓,通過cv::drawContours繪制輪廓
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <iostream>using namespace cv;
using namespace std;int threshold_value = 100;
int threshold_max = 255;
RNG rng;
const char* output_win = "Demo_Contour";
void Demo_Contours(int, void*);
Mat src,dst;
int main(int argc, char** argv) {src = imread("D:/photos/45.png");if (src.empty()) {printf("could not load image...\n");return -1;}namedWindow("input image", CV_WINDOW_AUTOSIZE);namedWindow(output_win, CV_WINDOW_AUTOSIZE);imshow("input image", src);cvtColor(src, src, CV_BGR2GRAY);//灰度化圖像,為Canny邊緣檢測(cè)做準(zhǔn)備const char* trackbar_title = "threshold_value";createTrackbar(trackbar_title, output_win, &threshold_value, threshold_max, Demo_Contours);//動(dòng)態(tài)調(diào)整Canny邊緣檢測(cè)的閾值Demo_Contours(0, 0);//使程序剛開始就有結(jié)果,與createTrackbar無關(guān)waitKey(0);return 0;
}void Demo_Contours(int, void*) {Mat canny_output;vector<vector<Point>> contours;vector<Vec4i> hierachy;Canny(src, canny_output, threshold_value, threshold_value * 2, 3, false);//Canny邊緣檢測(cè),3代表算子尺寸imshow("canny image", canny_output);findContours(canny_output, contours, hierachy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));//contours儲(chǔ)存輪廓的點(diǎn)集,輪廓提取方式為RETR_TREE,輪廓表達(dá)為:CHAIN_APPROX_SIMPLEdst = Mat::zeros(src.size(), CV_8UC3);RNG rng(12345);for (size_t i = 0; i < contours.size(); i++) {//逐條繪制輪廓Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));drawContours(dst, contours, i, color, 2, 8, hierachy, 0, Point(0, 0));}imshow(output_win, dst);}

在這里插入圖片描述

二.幾何及特性概括——凸包(Convex Hull)

凸包概念

什么是凸包(Convex Hull),在一個(gè)多變形邊緣或者內(nèi)部任意兩個(gè)點(diǎn)的連線都包含在多邊形邊界或者內(nèi)部。
**正式定義:**包含點(diǎn)集合S中所有點(diǎn)的最小凸多邊形稱為凸包

凸包掃描算法介紹——Graham掃描算法

  • 首先選擇Y方向最低的點(diǎn)作為起始點(diǎn)p0。
  • 從p0開始極坐標(biāo)掃描,依次添加p1….pn(排序順序是根據(jù)極坐標(biāo)的角度大小,逆時(shí)針方向)。
  • 對(duì)每個(gè)點(diǎn)pi來說,如果添加pi點(diǎn)到凸包中導(dǎo)致一個(gè)左轉(zhuǎn)向(逆時(shí)針方法)則添加該點(diǎn)到凸包,
    反之如果導(dǎo)致一個(gè)右轉(zhuǎn)向(順時(shí)針方向)刪除該點(diǎn)從凸包中。
    在這里插入圖片描述

相關(guān)API介紹

convexHull(
InputArray points,// 輸入候選點(diǎn),來自findContours
OutputArray hull,// 凸包
bool clockwise,// default true, 順時(shí)針方向
bool returnPoints)// true 表示返回點(diǎn)個(gè)數(shù),如果第二個(gè)參數(shù)是			vector<Point>則自動(dòng)忽略
}

凸包逼近實(shí)現(xiàn)步驟:

  • 首先把圖像從RGB轉(zhuǎn)為灰度。

  • 然后再轉(zhuǎn)為二值圖像。

  • 在通過發(fā)現(xiàn)輪廓得到候選點(diǎn)。

  • 凸包API調(diào)用。

  • 繪制顯示。

程序示例

#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <iostream>using namespace cv;
using namespace std;int threshold_value = 100;
int threshold_max = 255;
RNG rng(12345);
const char* output_win = "Demo_convex hull";
void threshold_callback(int, void*);
Mat src, dst,dst2,gray_src;
int main(int argc, char** argv) {src = imread("D:/photos/45.png");if (src.empty()) {printf("could not load image...\n");return -1;}namedWindow("input image", CV_WINDOW_AUTOSIZE);namedWindow(output_win, CV_WINDOW_AUTOSIZE);const char* trackbar_label = "threshold:";imshow("input image", src);cvtColor(src, gray_src, CV_BGR2GRAY);blur(gray_src, gray_src, Size(3, 3), Point(-1, -1), BORDER_DEFAULT);//均值模糊進(jìn)行降噪處理imshow("src_gray", gray_src);createTrackbar(trackbar_label, output_win, &threshold_value, threshold_max, threshold_callback);threshold_callback(0, 0);waitKey(0);return 0;
}
void threshold_callback(int, void*) {Mat bin_output;vector<vector<Point>> contours;vector<Vec4i> hierachy;threshold(gray_src, bin_output, threshold_value, threshold_max, THRESH_BINARY);findContours(bin_output, contours, hierachy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));vector<vector<Point>> convexs(contours.size());dst = Mat::zeros(src.size(), CV_8UC3);dst2 = Mat::zeros(src.size(), CV_8UC3);for (size_t i = 0; i < contours.size(); i++) {Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));convexHull(contours[i], convexs[i], false, true);//drawContours(dst, contours, i, color, 2, 8, hierachy, 0, Point(0, 0));}vector<Vec4i> empty(0);for (size_t k = 0; k < contours.size(); k++) {Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));drawContours(dst2, contours, k, color, 2, LINE_8, hierachy,1, Point(0, 0));drawContours(dst, convexs, k, color, 2, LINE_8, empty, 0, Point(0, 0));//注意此時(shí)hieracgy選項(xiàng)填Mat()}imshow(output_win, dst);imshow("contours_Demo", dst2);return;		
}

在這里插入圖片描述

輪廓集合及特性性概括——輪廓周圍繪制矩形框和圓形

相關(guān)理論介紹

在這里插入圖片描述

輪廓周圍繪制矩形 -API

approxPolyDP(InputArray curve, OutputArray approxCurve, double epsilon, bool closed)
基于RDP算法實(shí)現(xiàn),目的是減少多邊形輪廓點(diǎn)數(shù)。
在這里插入圖片描述

cv::minEnclosingCircle(InputArray points, //得到最小區(qū)域圓形
Point2f& center, // 圓心位置
float& radius)// 圓的半徑
cv::fitEllipse(InputArray points)得到最小橢圓

繪制步驟

首先將圖像變?yōu)槎祱D像。
發(fā)現(xiàn)輪廓,找到圖像輪廓。
通過相關(guān)API在輪廓點(diǎn)上找到最小包含矩形和圓,旋轉(zhuǎn)矩形與橢圓。
繪制它們。

程序?qū)嵗?/h2>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>using namespace std;
using namespace cv;
Mat src, gray_src, drawImg;
int threshold_v = 170;
int threshold_max = 255;
const char* output_win = "rectangle-demo";
RNG rng(12345);
void Contours_Callback(int, void*);
int main(int argc, char** argv) {src = imread("D:/photos/45.png");if (!src.data) {printf("could not load image...\n");return -1;}cvtColor(src, gray_src, CV_BGR2GRAY);blur(gray_src, gray_src, Size(3, 3), Point(-1, -1));const char* source_win = "input image";namedWindow(source_win, CV_WINDOW_AUTOSIZE);namedWindow(output_win, CV_WINDOW_AUTOSIZE);imshow(source_win, src);createTrackbar("Threshold Value:", output_win, &threshold_v, threshold_max, Contours_Callback);Contours_Callback(0, 0);waitKey(0);return 0;
}void Contours_Callback(int, void*) {Mat binary_output;vector<vector<Point>> contours;vector<Vec4i> hierachy;threshold(gray_src, binary_output, threshold_v, threshold_max, THRESH_BINARY);//imshow("binary image", binary_output);findContours(binary_output, contours, hierachy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(-1, -1));vector<vector<Point>> contours_ploy(contours.size());vector<Rect> ploy_rects(contours.size());vector<Point2f> ccs(contours.size());vector<float> radius(contours.size());vector<RotatedRect> minRects(contours.size());vector<RotatedRect> myellipse(contours.size());for (size_t i = 0; i < contours.size(); i++) {approxPolyDP(Mat(contours[i]), contours_ploy[i], 3, true);ploy_rects[i] = boundingRect(contours_ploy[i]);minEnclosingCircle(contours_ploy[i], ccs[i], radius[i]);if (contours_ploy[i].size() > 5) {myellipse[i] = fitEllipse(contours_ploy[i]);minRects[i] = minAreaRect(contours_ploy[i]);}}// draw itdrawImg = Mat::zeros(src.size(), src.type());Point2f pts[4];for (size_t t = 0; t < contours.size(); t++) {Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));//rectangle(drawImg, ploy_rects[t], color, 2, 8);//circle(drawImg, ccs[t], radius[t], color, 2, 8);if (contours_ploy[t].size() > 5) {ellipse(drawImg, myellipse[t], color, 1, 8);minRects[t].points(pts);for (int r = 0; r < 4; r++) {line(drawImg, pts[r], pts[(r + 1) % 4], color, 1, 8);}}}imshow(output_win, drawImg);return;
}

運(yùn)行效果:
在這里插入圖片描述

四.圖像矩(Image Moments)

1、相關(guān)理論

在這里插入圖片描述
在這里插入圖片描述

2、API介紹

1.計(jì)算矩cv::moments

moments(
InputArray  array,//輸入數(shù)據(jù)
bool   binaryImage=false // 是否為二值圖像
)

API介紹與使用 – cv::moments 計(jì)算生成數(shù)據(jù)在這里插入圖片描述

計(jì)算輪廓面積cv::contourArea

contourArea(
InputArray  contour,//輸入輪廓數(shù)據(jù)
bool   oriented// 默認(rèn)false、返回絕對(duì)值)
}

.計(jì)算輪廓長(zhǎng)度cv::arcLength

arcLength(
InputArray  curve,//輸入曲線數(shù)據(jù)
bool   closed// 是否是封閉曲線)
}

實(shí)現(xiàn)步驟:

提取圖像邊緣。
發(fā)現(xiàn)輪廓。
計(jì)算每個(gè)輪廓對(duì)象的矩。
計(jì)算每個(gè)對(duì)象的中心、弧長(zhǎng)、面積

例程

#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>using namespace std;
using namespace cv;Mat src, gray_src;
int threshold_value = 80;
int threshold_max = 255;
const char* output_win = "image moents demo";
RNG rng(12345);
void Demo_Moments(int, void*);
int main(int argc, char** argv) {src = imread("D:/photos/45.png");if (!src.data) {printf("could not load image...\n");return -1;}cvtColor(src, gray_src, CV_BGR2GRAY);GaussianBlur(gray_src, gray_src, Size(3, 3), 0, 0);char input_win[] = "input image";namedWindow(input_win, CV_WINDOW_AUTOSIZE);namedWindow(output_win, CV_WINDOW_AUTOSIZE);imshow(input_win, src);createTrackbar("Threshold Value : ", output_win, &threshold_value, threshold_max, Demo_Moments);Demo_Moments(0, 0);waitKey(0);return 0;
}void Demo_Moments(int, void*) {Mat canny_output;vector<vector<Point>> contours;vector<Vec4i> hierachy;Canny(gray_src, canny_output, threshold_value, threshold_value * 2, 3, false);findContours(canny_output, contours, hierachy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));vector<Moments> contours_moments(contours.size());vector<Point2f> ccs(contours.size());for (size_t i = 0; i < contours.size(); i++) {contours_moments[i] = moments(contours[i]);ccs[i] = Point(static_cast<float>(contours_moments[i].m10 / contours_moments[i].m00), static_cast<float>(contours_moments[i].m01 / contours_moments[i].m00));}Mat drawImg;// = Mat::zeros(src.size(), CV_8UC3);src.copyTo(drawImg);for (size_t i = 0; i < contours.size(); i++) {if (contours[i].size() < 100) {continue;}Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));printf("center point x : %.2f y : %.2f\n", ccs[i].x, ccs[i].y);printf("contours %d area : %.2f   arc length : %.2f\n", i, contourArea(contours[i]), arcLength(contours[i], true));drawContours(drawImg, contours, i, color, 2, 8, hierachy, 0, Point(0, 0));circle(drawImg, ccs[i], 2, color,2, 8);}imshow(output_win, drawImg);return;
}

在這里插入圖片描述

五、多邊形測(cè)試

1.相關(guān)理論

點(diǎn)多邊形測(cè)試 : 測(cè)試一個(gè)點(diǎn)是否在給定的多邊形內(nèi)部,邊緣或者外部。
在這里插入圖片描述

2.相關(guān)API介紹

cv::pointPolygonTest
pointPolygonTest(
InputArray  contour,// 輸入的輪廓
Point2f  pt, // 測(cè)試點(diǎn)
bool  measureDist // 是否返回距離值,如果是false,1表示在內(nèi)面,0表示在邊界上,-1表示在外部,true返回實(shí)際距離
)
返回?cái)?shù)據(jù)是double類型

程序示例

#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>using namespace std;
using namespace cv;
int main(int argc, char** argv) {const int r = 100;Mat src = Mat::zeros(r * 4, r * 4, CV_8UC1);vector<Point2f> vert(6);vert[0] = Point(3 * r / 2, static_cast<int>(1.34*r));   vert[1] = Point(1 * r, 2 * r);vert[2] = Point(3 * r / 2, static_cast<int>(2.866*r));   vert[3] = Point(5 * r / 2, static_cast<int>(2.866*r));vert[4] = Point(3 * r, 2 * r);   vert[5] = Point(5 * r / 2, static_cast<int>(1.34*r));for (int i = 0; i < 6; i++) {line(src, vert[i], vert[(i + 1) % 6], Scalar(255), 3, 8, 0);}vector<vector<Point>> contours;vector<Vec4i> hierachy;Mat csrc;src.copyTo(csrc);findContours(csrc, contours, hierachy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));Mat raw_dist = Mat::zeros(csrc.size(), CV_32FC1);for (int row = 0; row < raw_dist.rows; row++) {for (int col = 0; col < raw_dist.cols; col++) {double dist = pointPolygonTest(contours[0], Point2f(static_cast<float>(col), static_cast<float>(row)), true);raw_dist.at<float>(row, col) = static_cast<float>(dist);}}double minValue, maxValue;minMaxLoc(raw_dist, &minValue, &maxValue, 0, 0, Mat());Mat drawImg = Mat::zeros(src.size(), CV_8UC3);for (int row = 0; row < drawImg.rows; row++) {for (int col = 0; col < drawImg.cols; col++) {float dist = raw_dist.at<float>(row, col);if (dist > 0) {drawImg.at<Vec3b>(row, col)[0] = (uchar)(abs(1.0 - (dist / maxValue)) * 255);}else if (dist < 0) {drawImg.at<Vec3b>(row, col)[2] = (uchar)(abs(1.0 - (dist / minValue)) * 255);} else {drawImg.at<Vec3b>(row, col)[0] = (uchar)(abs(255 - dist));drawImg.at<Vec3b>(row, col)[1] = (uchar)(abs(255 - dist));drawImg.at<Vec3b>(row, col)[2] = (uchar)(abs(255 - dist));}}}const char* output_win = "point polygon test demo";char input_win[] = "input image";namedWindow(input_win, CV_WINDOW_AUTOSIZE);namedWindow(output_win, CV_WINDOW_AUTOSIZE);imshow(input_win, src);imshow(output_win, drawImg);waitKey(0);return 0;
}

在這里插入圖片描述

http://m.aloenet.com.cn/news/41036.html

相關(guān)文章:

  • 公司網(wǎng)站制作 步驟seo優(yōu)化師是什么
  • 網(wǎng)站備案值得嗎常見的搜索引擎
  • 做機(jī)械設(shè)計(jì)的要知道哪些網(wǎng)站產(chǎn)品優(yōu)化是什么意思
  • 深圳外貿(mào)網(wǎng)站建設(shè)公司企業(yè)管理培訓(xùn)班
  • 濟(jì)南哪里有建網(wǎng)站seo公司怎樣找客戶
  • 網(wǎng)站上的截圖怎么做動(dòng)態(tài)網(wǎng)站的制作與設(shè)計(jì)
  • 玉溪網(wǎng)絡(luò)推廣 網(wǎng)站建設(shè)國外網(wǎng)站加速
  • 寧波做日用品外貿(mào)公司網(wǎng)站百度搜索引擎原理
  • 湖北網(wǎng)站建設(shè)找哪家如何做好營(yíng)銷推廣
  • asp.net網(wǎng)站安全太原網(wǎng)站制作優(yōu)化seo公司
  • 安順住房和城鄉(xiāng)建設(shè)部網(wǎng)站網(wǎng)站app開發(fā)公司
  • 昆山做網(wǎng)站的公司有哪些關(guān)鍵詞免費(fèi)
  • 德陽企業(yè)品牌網(wǎng)站建設(shè)seo網(wǎng)站推廣公司
  • 聚美優(yōu)品一個(gè)專注于做特價(jià)的網(wǎng)站活動(dòng)推廣軟文
  • 建站系統(tǒng)磁力搜索引擎不死鳥
  • 織夢(mèng)做網(wǎng)站的教程短視頻代運(yùn)營(yíng)合作方案
  • 吃什么補(bǔ)腎虛效果最好食物焦作整站優(yōu)化
  • 2018網(wǎng)站的建設(shè)與維護(hù)前景網(wǎng)店代運(yùn)營(yíng)商
  • 鎮(zhèn)江做網(wǎng)站的做網(wǎng)站用什么編程軟件
  • 科技網(wǎng)站 網(wǎng)站建設(shè)廣告公司業(yè)務(wù)推廣
  • 網(wǎng)站開發(fā)需解決什么問題廣州百度關(guān)鍵詞搜索
  • 用html做班級(jí)網(wǎng)站萬網(wǎng)域名注冊(cè)信息查詢
  • 有道翻譯網(wǎng)站 做翻譯太原網(wǎng)站推廣排名
  • c做網(wǎng)站百度云登錄
  • wordpress首頁加登錄在線seo短視頻
  • 免費(fèi)學(xué)校網(wǎng)站管理系統(tǒng)南京百度seo排名
  • 有哪些做婚禮電子請(qǐng)柬的網(wǎng)站品牌推廣活動(dòng)策劃方案
  • 榆林免費(fèi)做網(wǎng)站推廣引流渠道
  • 如何做分類網(wǎng)站信息營(yíng)銷市場(chǎng)調(diào)研一般怎么做
  • 惠州做網(wǎng)站 百度優(yōu)化線上宣傳渠道和宣傳方式