最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

opencv實(shí)現(xiàn)輪廓高斯濾波平滑

 更新時(shí)間:2020年07月21日 14:35:25   作者:BHY_  
這篇文章主要為大家詳細(xì)介紹了opencv實(shí)現(xiàn)輪廓高斯濾波平滑,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了opencv實(shí)現(xiàn)輪廓高斯濾波平滑的具體代碼,供大家參考,具體內(nèi)容如下

一個(gè)小測(cè)試的題目:

在圖像上點(diǎn)選,找到與點(diǎn)選處相鄰的顏色相近的點(diǎn)集合,對(duì)該點(diǎn)集合提取輪廓,對(duì)該點(diǎn)集合輪廓平滑處理,顯示處理結(jié)果。

#include <opencv2/opencv.hpp>
#include <iostream>
 
using namespace std;
using namespace cv;
 
 
//************************************
// Method: findRegion 漫水填充
// FullName: findRegion
// Access: public 
// Returns: vector<Point>
// Qualifier:
// Parameter: Mat img
// Parameter: Point pos
// Parameter: int LowDifference
// Parameter: int UpDifference
//************************************
vector<Point> findRegion(Mat img, Point pos, int LowDifference, int UpDifference)
{
 Mat image = img.clone();
 Mat imgBack = img.clone();
 Rect ccomp;
 Scalar pixel = image.at<Vec3b>(pos);
 Scalar pixel2 = Scalar(255 - pixel[0], 255 - pixel[1], 255 - pixel[2], pixel[3]);
 floodFill(image, pos, pixel2, &ccomp, Scalar(LowDifference, LowDifference, LowDifference),
 Scalar(UpDifference, UpDifference, UpDifference));
 
 Mat diff;
 absdiff(image, imgBack, diff);
 
 //統(tǒng)計(jì)所有非零像素
 vector<Point> pt;
 for (int i = 0; i < diff.rows; i++)
 {
 for (int j = 0; j < diff.cols; j++)
 {
 Point newPos(j, i);
 Scalar pixel3 = diff.at<Vec3b>(newPos);
 if (pixel3[0] != 0 || pixel3[1] != 0 || pixel3[2] != 0)
 {
 pt.push_back(newPos);
 }
 }
 }
 
 return pt;
}
 
//************************************
// Method: findPerimeter 從點(diǎn)集合中尋找輪廓點(diǎn)
// FullName: findPerimeter
// Access: public 
// Returns: vector<Point>
// Qualifier:
// Parameter: vector<Point> pt
// Parameter: Size size
//************************************
vector<Point> findPerimeter(vector<Point> pt, Size size)
{
 Mat imgGray(size, CV_8UC1, Scalar(0));
 for (int i = 0; i < pt.size(); i++)
 {
 imgGray.at<uchar>(pt[i]) = 255;
 }
 
 std::vector<std::vector<cv::Point>> contours;
 //獲取輪廓不包括輪廓內(nèi)的輪廓 
 cv::findContours(imgGray.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
 
 return contours[0];
}
 
//************************************
// Method: displayImage 顯示圖像
// FullName: displayImage
// Access: public 
// Returns: void
// Qualifier:
// Parameter: Mat img
// Parameter: vector<Point> contours 輪廓點(diǎn)
// Parameter: Point pos
//************************************
void displayImage(Mat img, vector<Point> contours, Point pos)
{
 Mat imgShow = img.clone();
 for (int i = 0; i < contours.size(); i++)
 {
 imgShow.at<Vec3b>(contours[i])[0] = 0;
 imgShow.at<Vec3b>(contours[i])[1] = 0;
 imgShow.at<Vec3b>(contours[i])[2] = 0;
 }
 
 circle(imgShow, pos, 3, Scalar(0, 0, 0), 1, 8, 0);//畫用戶選擇的點(diǎn)
 
 imshow("img", imgShow);
 waitKey(0);
}
 
 
//************************************
// Method: findSmoothPeimeter 高斯濾波輪廓點(diǎn)平滑
// FullName: findSmoothPeimeter
// Access: public 
// Returns: void
// Qualifier:
// Parameter: Mat img 原圖
// Parameter: vector<Point> pt 輪廓點(diǎn)集合
//************************************
void findSmoothPeimeter(Mat img, vector<Point> pt)
{
 vector<Point> contours = findPerimeter(pt, img.size());
 
 Mat im;
 cvtColor(img, im, CV_BGR2GRAY);
 
 Mat cont = ~im;
 Mat original = Mat::zeros(im.rows, im.cols, CV_8UC3);
 Mat smoothed = img.clone();
 
 // contour smoothing parameters for gaussian filter
 int filterRadius = 10;
 int filterSize = 2 * filterRadius + 1;
 double sigma = 10;
 
 size_t len = contours.size() + 2 * filterRadius;
 size_t idx = (contours.size() - filterRadius);
 vector<float> x, y;
 for (size_t i = 0; i < len; i++)
 {
 x.push_back(contours[(idx + i) % contours.size()].x);
 y.push_back(contours[(idx + i) % contours.size()].y);
 }
 // filter 1-D signals
 vector<float> xFilt, yFilt;
 GaussianBlur(x, xFilt, Size(filterSize, filterSize), sigma, sigma);
 GaussianBlur(y, yFilt, Size(filterSize, filterSize), sigma, sigma);
 // build smoothed contour
 vector<Point> smoothContours;
 for (size_t i = filterRadius; i < contours.size() + filterRadius; i++)
 {
 smoothContours.push_back(Point(xFilt[i], yFilt[i]));
 }
 
 Scalar color;
 
 for (int i = 0; i < smoothContours.size(); i++)
 {
 smoothed.at<Vec3b>(smoothContours[i])[0] = 0;
 smoothed.at<Vec3b>(smoothContours[i])[1] = 0;
 smoothed.at<Vec3b>(smoothContours[i])[2] = 0;
 }
 
 imshow("smoothed", smoothed);
 waitKey(10);
}
 
void main()
{
 Mat img = imread("4.jpg", 1);
 
 vector<Point> pt, contours;
 Point pos(1438, 590);//先列后行
 int para1 = 2;
 int para2 = 2;
 pt = findRegion(img, pos, para1, para2);
 findSmoothPeimeter(img, pt);
 
 contours = findPerimeter(pt, img.size());//輪廓點(diǎn)集合
 displayImage(img, contours, pos);//顯示圖像
}

漫水填充找到的輪廓

輪廓濾波平滑

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C語言for循環(huán)嵌套for循環(huán)在實(shí)踐題目中應(yīng)用詳解

    C語言for循環(huán)嵌套for循環(huán)在實(shí)踐題目中應(yīng)用詳解

    初學(xué)C語言,常常遇到for循環(huán)中嵌套個(gè)for循環(huán),初學(xué)者對(duì)于這種形式總是一知半解,這次我就整理了常見的for循環(huán)嵌套for循環(huán)的題目,我們一起爭(zhēng)取一舉拿下這類題。學(xué)廢他們,以后再見到就不怕啦!每天都要學(xué)一點(diǎn)呀。加油,奮斗的我們
    2022-05-05
  • C++中CopyFile和MoveFile函數(shù)使用區(qū)別的示例分析

    C++中CopyFile和MoveFile函數(shù)使用區(qū)別的示例分析

    這篇文章主要介紹了C++中CopyFile和MoveFile函數(shù)使用區(qū)別的示例分析,CopyFile表示將文件A拷貝到B,如果B已經(jīng)存在則覆蓋,MoveFile表示將文件A移動(dòng)到。對(duì)此感興趣的可以來了解一下
    2020-07-07
  • 詳解C++中StringBuilder類的實(shí)現(xiàn)及其性能優(yōu)化

    詳解C++中StringBuilder類的實(shí)現(xiàn)及其性能優(yōu)化

    在Java和C#中,StringBuilder可以創(chuàng)造可變字符序列來動(dòng)態(tài)地?cái)U(kuò)充字符串,那么在C++中我們同樣也可以實(shí)現(xiàn)一個(gè)StringBuilder并且用來提升性能,下面就來詳解C++中StringBuilder類的實(shí)現(xiàn)及其性能優(yōu)化
    2016-05-05
  • C語言判斷數(shù)是否為素?cái)?shù)與素?cái)?shù)輸出

    C語言判斷數(shù)是否為素?cái)?shù)與素?cái)?shù)輸出

    大家好,本篇文章主要講的是C語言判斷數(shù)是否為素?cái)?shù)與素?cái)?shù)輸出,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • 求32位機(jī)器上unsigned int的最大值及int的最大值的解決方法

    求32位機(jī)器上unsigned int的最大值及int的最大值的解決方法

    本篇文章是對(duì)求32位機(jī)器上unsigned int的最大值及int的最大值的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • C語言計(jì)算Robots機(jī)器人行走路線

    C語言計(jì)算Robots機(jī)器人行走路線

    這篇文章介紹了C語言計(jì)算Robots機(jī)器人行走路線,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-12-12
  • C語言使用廣度優(yōu)先搜索算法解決迷宮問題(隊(duì)列)

    C語言使用廣度優(yōu)先搜索算法解決迷宮問題(隊(duì)列)

    這篇文章主要介紹了C語言使用廣度優(yōu)先搜索算法解決迷宮問題,結(jié)合迷宮問題分析了C語言隊(duì)列廣度優(yōu)先搜索算法的相關(guān)使用技巧,需要的朋友可以參考下
    2017-09-09
  • libxml教程(圖文詳解)

    libxml教程(圖文詳解)

    本篇文章是對(duì)libxm進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • C++ Boost Array與Unordered使用介紹

    C++ Boost Array與Unordered使用介紹

    Boost是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱。Boost庫是一個(gè)可移植、提供源代碼的C++庫,作為標(biāo)準(zhǔn)庫的后備,是C++標(biāo)準(zhǔn)化進(jìn)程的開發(fā)引擎之一,是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱
    2022-11-11
  • 從頭學(xué)習(xí)C語言之if語句的使用

    從頭學(xué)習(xí)C語言之if語句的使用

    這篇文章主要為大家詳細(xì)介紹了C語言之if語句的使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-01-01

最新評(píng)論

灵台县| 高阳县| 同德县| 绩溪县| 新余市| 广汉市| 新安县| 美姑县| 砚山县| 夏津县| 北海市| 晴隆县| 永靖县| 吉安市| 临漳县| 景东| 庆云县| 汤阴县| 鄢陵县| 安西县| 宝坻区| 定安县| 隆昌县| 揭东县| 南投市| 馆陶县| 文山县| 岳阳市| 双辽市| 永靖县| 海淀区| 宜兴市| 金山区| 霍山县| 恩平市| 西吉县| 大英县| 新乐市| 长乐市| 兴海县| 油尖旺区|