我不会C,求大神帮我转成matlab语言吧,急
void canny(cv::Mat &img,cv::Mat &out){
// 初始化Canny函数的阈值
double low = 0.0, high = 0.0;
// 自适应设定阈值
AdaptiveFindThreshold(img, &low, &high);
// 灰度转换
if(img.channels() == 3)
cv::cvtColor(img,out,CV_BGR2GRAY);
// 只保留天空区域
int skyroi_row = out.rows*1/4;
int skyroi_col = out.cols;
out = out(Rect(0,skyroi_row,skyroi_col,skyroi_row));
// 直方图均衡化处理
cv::equalizeHist(out,out);
// 边缘检测
// cout<<"low:"<<low<<endl;
// cout<<"high:"<<high<<endl;
cv::Canny(out,out,low,high);
// 判断是否存在镜头污染
cv::Mat_<uchar>::iterator it; // 判断指令初始迭代器
cv::Mat_<uchar>::iterator itend; // 判断指令终止迭代器
long roi_area = 0; // 判断区域大小
it = out.begin<uchar>();
itend = out.end<uchar>();
for(;it != itend;++it){ // 检测选定区域前景面积
if(*it == 255)
roi_area++;
}
double proportion = double(roi_area)/double(out.rows*out.cols); // 前景面积占区域面积百分比
// cout<<roi_area<<endl;
// cout<<out.rows*out.cols<<endl;
// cout<<proportion<<endl;
std::vector<std::vector<cv::Point>>contours;
cv::findContours(out,contours, // 轮廓的数组
CV_RETR_EXTERNAL, // 获取外轮廓
CV_CHAIN_APPROX_NONE); // 获取每个轮廓的每个像素
// cv::Mat result(out.size(),CV_8U,cv::Scalar(255)); // 显示所获得的轮廓
// cv::drawContours(result,contours,-1,cv::Scalar(0),1);
// cv::namedWindow("Contours");
// cv::imshow("Contours",result);
// cout<<contours.size()<<endl;
if(contours.size() >= 35 || proportion >= 0.08){
frame_count_2++;
frame_count_2 = min(50,frame_count_2);
}
else{
frame_count_2--;
frame_count_2 = max(0,frame_count_2);
}
void canny(cv::Mat &img,cv::Mat &out){
// 初始化Canny函数的阈值
double low = 0.0, high = 0.0;
// 自适应设定阈值
AdaptiveFindThreshold(img, &low, &high);
// 灰度转换
if(img.channels() == 3)
cv::cvtColor(img,out,CV_BGR2GRAY);
// 只保留天空区域
int skyroi_row = out.rows*1/4;
int skyroi_col = out.cols;
out = out(Rect(0,skyroi_row,skyroi_col,skyroi_row));
// 直方图均衡化处理
cv::equalizeHist(out,out);
// 边缘检测
// cout<<"low:"<<low<<endl;
// cout<<"high:"<<high<<endl;
cv::Canny(out,out,low,high);
// 判断是否存在镜头污染
cv::Mat_<uchar>::iterator it; // 判断指令初始迭代器
cv::Mat_<uchar>::iterator itend; // 判断指令终止迭代器
long roi_area = 0; // 判断区域大小
it = out.begin<uchar>();
itend = out.end<uchar>();
for(;it != itend;++it){ // 检测选定区域前景面积
if(*it == 255)
roi_area++;
}
double proportion = double(roi_area)/double(out.rows*out.cols); // 前景面积占区域面积百分比
// cout<<roi_area<<endl;
// cout<<out.rows*out.cols<<endl;
// cout<<proportion<<endl;
std::vector<std::vector<cv::Point>>contours;
cv::findContours(out,contours, // 轮廓的数组
CV_RETR_EXTERNAL, // 获取外轮廓
CV_CHAIN_APPROX_NONE); // 获取每个轮廓的每个像素
// cv::Mat result(out.size(),CV_8U,cv::Scalar(255)); // 显示所获得的轮廓
// cv::drawContours(result,contours,-1,cv::Scalar(0),1);
// cv::namedWindow("Contours");
// cv::imshow("Contours",result);
// cout<<contours.size()<<endl;
if(contours.size() >= 35 || proportion >= 0.08){
frame_count_2++;
frame_count_2 = min(50,frame_count_2);
}
else{
frame_count_2--;
frame_count_2 = max(0,frame_count_2);
}