1、常用算法寻找边界
std::vector<std::vector<cv::Point>> contours;
findContours( imgLast, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
cv::Mat imgMask( matBrokeRoi.size(), CV_8UC1, cv::Scalar(0) );
for ( unsigned int i=0; i < contours.size(); i++ )
{
double targetArea = contourArea(contours[i]);
cv::Rect rect = cv::boundingRect(contours[i]);
drawContours(imgMask, contours, (int)i, cv::Scalar::all(255), -1, 8);
}
2、点中寻找最小包围圆形
Point2f center;
float radius;
minEnclosingCircle(points, center, radius);
3.包含点的 最小矩形
rect = minAreaRect(InputArray points)
4.与四边平行的正矩形
Rect boundingRect(InputArray points)
5.自定义卷积
#include <opencv2/opencv.hpp>
int main ()
{
cv::Mat imgSrc,imgGrad;
imgSrc=cv::imread("12.jpg");
cv::Mat fkernel = cv::Mat(2, 1, CV_32FC1, cv::Scalar(0) );
fkernel.at<float>(0,0) = -1;
fkernel.at<float>(1,0) = 1;
//Filter_kernel_Vert.at<float>(2,0) = 1;
cv::resize( imgSrc, imgSrc, cv::Size( imgSrc.cols / 2, imgSrc.rows / 2 ) );
cv::filter2D( imgSrc, imgGrad, imgSrc.depth(), fkernel );
cv::imshow("temp2",imgGrad);
cv::waitKey(0);
return 0;
}
6、膨胀 与腐蚀
cv::Mat KerForCannyEro = cv::Mat(3, 9, CV_8UC1, cv::Scalar(1) );
cv::dilate( matCanny, matCannyDilate, KerForCannyEro );
cv::erode( matCanny, matCannyDilate, KerForCannyEro )
7、翻转
cv::flip(imgSrc,imgOut,1);