#include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; // image threshold threshold // 1. Binarize threshold binary // greater than the threshold equal to 255 (white) less than the threshold equal to 0 (black) (when the threshold is 0, it is all white; when the threshold is 255, the original black) // 2. Threshold binary inverted // greater than the threshold equal to 0 (black) less than the threshold equal to 255 (white) (when the threshold is 0, all black; when the threshold is 255, all white) // 3. Truncate truncate // Greater than the threshold equal to the threshold less than the threshold unchanged (when the threshold is 0, it is completely black; when the threshold is 255, the original image) // 4. threshold to zero // Greater than the threshold and unchanged less than the threshold equal to 0 (black) (when the threshold is 0, the original image; when the threshold is 255, it is all black) // 5. Threshold to zero inverted // greater than the threshold equal to 0 (black) less than the threshold unchanged (when the threshold is 0, it is completely black; when the threshold is 255, the original image) // THRESH_OTSU THRESH_TRIANGLE automatically find the threshold Mat src1, src2, gray_src, dst; int threshold_value = 127; int threshold_max = 255; int type_value = 0; int type_max = 4; void Threshold_Demo(int, void*) { threshold(gray_src, dst, threshold_value, threshold_max, type_value); imshow("Threshold Demo", dst); } int main() { src1 = imread("/Users/apple/Desktop/fapiao.jpg", IMREAD_COLOR); //src2 = imread("/Users/apple/Desktop/test2.jpg", IMREAD_COLOR); if (src1.empty()) { // if (!src.data()) cout << "could not load image..." << endl; return -1; } //imshow("input", src1); cvtColor(src1, gray_src, CV_BGR2GRAY); namedWindow("Threshold Demo", WINDOW_AUTOSIZE); imshow("Threshold Demo", gray_src); createTrackbar("Threshold Value: ", "Threshold Demo", &threshold_value, threshold_max, Threshold_Demo); createTrackbar("Type Value: ", "Threshold Demo", &type_value, type_max, Threshold_Demo); Threshold_Demo(0 , 0); waitKey(0); return 0; }
OpenCV threshold operation
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325734573&siteId=291194637
Recommended
Ranking