图像处理基础2

Mat src, dst;

int threshold_value = 127;

int threshold_max = 255;

const char* output_title = "binary image";

void Threshold_dome(int, void*);

Mat gray_src;

int type_value = 2;

int type_max = 5;

 

 int main(int argc, char** argv) {

     

     // 形态学

     char output_win[] = "output image";

     src = imread("D:/opencvsp/pic.png");

     if (!src.data)

     {

          printf("could not load image..\n");

          return -1;

     }

     namedWindow("input img", WINDOW_AUTOSIZE);

     imshow("input img", src);

     //上采样

     pyrUp(src, dst, Size(src.cols * 2, src.rows * 2));

    //降采样

     pyrDown(src, dst, Size(src.cols / 2, src.rows / 2));

     //DOG

     Mat gray_src, g1, g2, dogImg;

     cvtColor(src, gray_src, COLOR_BGR2GRAY);

     GaussianBlur(gray_src, g1, Size(3, 3), 0, 0);

     GaussianBlur(g1, g2, Size(3, 3), 0);

     subtract(g1, g2, dogImg, Mat());

     //归一化

     normalize(dogImg, dogImg, 255, 0, NORM_MINMAX);

     imshow("dogImg", dogImg);

 

 

 

     ///基本阈值操作

     createTrackbar("threshold value:", output_title,&threshold_value,threshold_max, Threshold_dome);

     createTrackbar("threshold value:", output_title, &type_value, type_max, Threshold_dome);

     

     waitKey(0);

     return 0;

 }

 void Threshold_Demo(int, void*) {

     cvtColor(src, gray_src, COLOR_BGR2GRAY);

     //threshold(gray_src, dst, threshold_value, threshold_max, type_value);

     threshold(gray_src, dst, 0, 255, THRESH_OTSU|type_value);  //THRESH_TRIANGLE

     imshow(output_title, dst);

 }

上一篇:[4-2]特色皮肤模仿(TikTok+Pornhub+Intellij)


下一篇:opencv实战-文档扫描