void testSobel(string fname)
{
Mat img = imread(fname);
Mat img1,img2,img3;
Sobel(img, img1,CV_32F ,0, 1);
Sobel(img, img2, CV_32F, 1, 0);
convertScaleAbs(img1, img1, 2.0);
convertScaleAbs(img2, img2, 2.0);
img3 = img1 + img2;
imwrite(“ROI3.png”, img1+img2);
}
int main(int argc, char **argv)
{
if (argc < 2) return 0;
int i=2;
if (string(argv[1]) == “ROIG”) //ROIG 20200104150237(20318069).jpg
{
ROI(argv[2]);
}
else if (string(argv[1]) == “SOBEL”) //SOBEL ROI.png
{
testSobel(string(argv[2]));
}
return 0;
}
1.Sobel算子的用法
CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth,
int dx, int dy, int ksize = 3,
double scale = 1, double delta = 0,
int borderType = BORDER_DEFAULT );
src是原图,dst是修改过的图,ddepth是位深度,dx=1,dy=0是x方向求差分;dx=0,dy=1是y方向求差分;borderType是边缘的处理方法;
2.convertScale()能够将图片的类型转换;
3.string能够获得一个无名的字符串类型的变量。