#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include
#include
#include
using namespace cv;
int main()
{
Mat img0,img, img1, img2, img3, img4, img5;
int yuzhi = 122;//设置图像阈值
img0 = imread("D://xlxl//32.jpg");
int width01 = 500, higth01 = 300;//设置输出图像大小,移动方位
cvtColor(img0, img, COLOR_RGB2GRAY);//转为灰度图
threshold(img, img1, yuzhi, 255, THRESH_BINARY);
threshold(img, img2, yuzhi, 255, THRESH_BINARY_INV);
threshold(img, img3, yuzhi, 255, THRESH_TRUNC);
threshold(img, img4, yuzhi, 255, THRESH_TOZERO);
threshold(img, img5, yuzhi, 255, THRESH_TOZERO_INV);
namedWindow("二值图像01", WINDOW_NORMAL);
resizeWindow("二值图像01", width01, higth01);
moveWindow("二值图像01", width01, higth01);
imshow("二值图像01", img1);
namedWindow("二值图像02", WINDOW_NORMAL);
resizeWindow("二值图像02", width01, higth01);
moveWindow("二值图像02", width01, higth01);
imshow("二值图像02", img2);
namedWindow("二值图像03", WINDOW_NORMAL);
resizeWindow("二值图像03", width01, higth01);
moveWindow("二值图像03", width01, higth01);
imshow("二值图像03", img3);
namedWindow("二值图像04", WINDOW_NORMAL);
resizeWindow("二值图像04", width01, higth01);
moveWindow("二值图像04", width01, higth01);
imshow("二值图像04", img4);
namedWindow("二值图像05", WINDOW_NORMAL);
resizeWindow("二值图像05", width01, higth01);
moveWindow("二值图像05", width01, higth01);
imshow("二值图像05", img5);
waitKey(0);
system("pause");
}
随意调整好的效果如图: