欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

OpenCV連通域數(shù)量統(tǒng)計(jì)學(xué)習(xí)示例

 更新時(shí)間:2022年06月07日 09:05:19   作者:忘·月  
這篇文章主要為大家介紹了OpenCV連通域數(shù)量統(tǒng)計(jì)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

學(xué)習(xí)目標(biāo):

1.輸入圖像為分割結(jié)果圖像

2.根據(jù)種子填充法思路,遍歷圖像,得到每個(gè)連通域外接矩形坐標(biāo)信息、面積信息

核心代碼

/*
	Input:
		src: 待檢測(cè)連通域的二值化圖像
	Output:
		dst: 標(biāo)記后的圖像
		featherList: 連通域特征的清單(可自行查閱文檔)
	return:
		連通域數(shù)量。
*/
int connectionDetect(Mat &src, Mat &dst, vector<Feather> &featherList)
{
	int rows = src.rows;
	int cols = src.cols;
	int labelValue = 0;
	Point seed, neighbor;
	stack<Point> pointStack;
	// 用于計(jì)算連通域的面積
	int area = 0;         
	// 連通域的左邊界,即外接最小矩形的左邊框,橫坐標(biāo)值,依此類(lèi)推
	int leftBoundary = 0;       
	int rightBoundary = 0;
	int topBoundary = 0;
	int bottomBoundary = 0;
	// 外接矩形框
	Rect box;                   
	Feather feather;
	vector<stack<Point>> points;
	featherList.clear();
	dst.release();
	dst = src.clone();
	for (int i = 0; i < rows; i++)
	{
		uchar *pRow = dst.ptr<uchar>(i);
		for (int j = 0; j < cols; j++)
		{
			if (pRow[j] == 255)
			{
				area = 0;
				// labelValue最大為254,最小為1.
				labelValue++;       
				// Point(橫坐標(biāo),縱坐標(biāo))
				seed = Point(j, i);     
				dst.at<uchar>(seed) = labelValue;
				pointStack.push(seed);
				area++;
				leftBoundary = seed.x;
				rightBoundary = seed.x;
				topBoundary = seed.y;
				bottomBoundary = seed.y;
				while (!pointStack.empty())
				{
					neighbor = Point(seed.x + 1, seed.y);
					if ((seed.x != (cols - 1)) && (dst.at<uchar>(neighbor) == 255))
					{
						dst.at<uchar>(neighbor) = labelValue;
						pointStack.push(neighbor);
						area++;
						if (rightBoundary < neighbor.x)
							rightBoundary = neighbor.x;
					}
					neighbor = Point(seed.x, seed.y + 1);
					if ((seed.y != (rows - 1)) && (dst.at<uchar>(neighbor) == 255))
					{
						dst.at<uchar>(neighbor) = labelValue;
						pointStack.push(neighbor);
						area++;
						if (bottomBoundary < neighbor.y)
							bottomBoundary = neighbor.y;
					}
					neighbor = Point(seed.x - 1, seed.y);
					if ((seed.x != 0) && (dst.at<uchar>(neighbor) == 255))
					{
						dst.at<uchar>(neighbor) = labelValue;
						pointStack.push(neighbor);
						area++;
						if (leftBoundary > neighbor.x)
							leftBoundary = neighbor.x;
					}
					neighbor = Point(seed.x, seed.y - 1);
					if ((seed.y != 0) && (dst.at<uchar>(neighbor) == 255))
					{
						dst.at<uchar>(neighbor) = labelValue;
						pointStack.push(neighbor);
						area++;
						if (topBoundary > neighbor.y)
							topBoundary = neighbor.y;
					}
					seed = pointStack.top();
					pointStack.pop();
				}
				box = Rect(leftBoundary, topBoundary, rightBoundary - leftBoundary, bottomBoundary - topBoundary);
				feather.area = area;
				feather.boundingbox = box;
				feather.label = labelValue;
				featherList.push_back(feather);
			}
		}
	}
	return labelValue;
}

 代碼執(zhí)行說(shuō)明

<font color=#999AAA >在此不進(jìn)行實(shí)例演示

1、 輸入圖像為分割后圖像

2、 執(zhí)行結(jié)果可根據(jù)featherList信息自行繪制矩形框

<hr style=" border:solid; width:100px; height:1px;" color=#000000 size=1">

以上就是OpenCV連通域數(shù)量統(tǒng)計(jì)學(xué)習(xí)示例的詳細(xì)內(nèi)容,更多關(guān)于OpenCV連通域數(shù)量統(tǒng)計(jì)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python 用matplotlib畫(huà)以時(shí)間日期為x軸的圖像

    Python 用matplotlib畫(huà)以時(shí)間日期為x軸的圖像

    這篇文章主要介紹了Python 用matplotlib畫(huà)以時(shí)間日期為x軸的圖像,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • 深入解析Python中的多進(jìn)程

    深入解析Python中的多進(jìn)程

    這篇文章主要介紹了深入解析Python中的多進(jìn)程,“Python中的多進(jìn)程是通過(guò)multiprocessing包來(lái)實(shí)現(xiàn)的,和多線程的threading.Thread差不多,它可以利用multiprocessing.Process對(duì)象來(lái)創(chuàng)建一個(gè)進(jìn)程對(duì)象
    2022-06-06
  • Python?Pandas中DataFrame.drop_duplicates()刪除重復(fù)值詳解

    Python?Pandas中DataFrame.drop_duplicates()刪除重復(fù)值詳解

    在實(shí)際處理數(shù)據(jù)中,數(shù)據(jù)預(yù)處理操作中,常常需要去除掉重復(fù)的數(shù)據(jù),這篇文章主要給大家介紹了關(guān)于Python?Pandas中DataFrame.drop_duplicates()刪除重復(fù)值的相關(guān)資料,需要的朋友可以參考下
    2022-07-07
  • Python 解析xml文件的示例

    Python 解析xml文件的示例

    這篇文章主要介紹了Python 解析xml文件的示例,幫助大家更好的利用python處理文件,感興趣的朋友可以了解下
    2020-09-09
  • Python文件及目錄處理的方法

    Python文件及目錄處理的方法

    這篇文章主要介紹了Python文件及目錄處理的方法,Python可以用于處理文本文件和二進(jìn)制文件,比如創(chuàng)建文件、讀寫(xiě)文件等操作。本文介紹Python處理目錄以及文件的相關(guān)資料,需要的朋友可以參考一下
    2021-12-12
  • Python根據(jù)當(dāng)前日期取去年同星期日期

    Python根據(jù)當(dāng)前日期取去年同星期日期

    最近做項(xiàng)目,遇到這樣的業(yè)務(wù)開(kāi)發(fā)需求,需要對(duì)比當(dāng)前時(shí)間段和去年同星期的時(shí)間段的數(shù)據(jù),下面小編通過(guò)實(shí)例代碼給大家分享Python根據(jù)當(dāng)前日期取去年同星期日期,需要的朋友參考下
    2019-04-04
  • 一起來(lái)了解python的基本輸入和輸出

    一起來(lái)了解python的基本輸入和輸出

    這篇文章主要為大家詳細(xì)介紹了python的基本輸入和輸出,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-02-02
  • Python使用Kubernetes API訪問(wèn)集群

    Python使用Kubernetes API訪問(wèn)集群

    本文主要介紹了Python使用Kubernetes API訪問(wèn)集群,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • python求列表對(duì)應(yīng)元素的乘積和的實(shí)現(xiàn)

    python求列表對(duì)應(yīng)元素的乘積和的實(shí)現(xiàn)

    這篇文章主要介紹了python求列表對(duì)應(yīng)元素的乘積和的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • python環(huán)境的報(bào)錯(cuò)解決方法

    python環(huán)境的報(bào)錯(cuò)解決方法

    這篇文章主要為大家介紹了python環(huán)境的報(bào)錯(cuò)解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08

最新評(píng)論