图像处理小知识随手记

1.阈值常采用OTSU方法,其主要思想是利用图像的灰度直方图,以目标和背景的方差最大来动态的确定图像分割的阈值。

2.matlab里处理单个区域的有regionprops函数,opencv里可以用findContours实现针对单个区域处理,见代码如下:

 1 findContours(aftColorResult, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
 2     // fill external contours
 3     if (!contours.empty() && !hierarchy.empty())
 4     {
 5         for (int idx = 0; idx < contours.size(); idx++)
 6         {
 7 
 8             drawContours(aftColorResult, contours, idx, Scalar(255), CV_FILLED, 8);//filled the region
 9             Mat eachBianryRegion(aftColorResult.size(), CV_8U, Scalar(0));//建立个空的Mat矩阵
10             drawContours(eachBianryRegion, contours, idx, Scalar(255), CV_FILLED, 8);
11             12 
13         }
原文地址:https://www.cnblogs.com/ggYYa/p/6230525.html