Skip to content

Instantly share code, notes, and snippets.

View hkhojasteh's full-sized avatar
☁️
From the top of the clouds.

Hadi Abdi Khojasteh hkhojasteh

☁️
From the top of the clouds.
View GitHub Profile
Mat mask_hsv_yellow, mask_white, img_mask;
//Make target image by apply yellow and white mask
Scalar m = mean(img_gray);
cvtColor(img, mask_hsv_yellow, CV_BGR2HSV);
inRange(img_crop, Scalar(20, 85, 85), Scalar(30, 255, 255), mask_hsv_yellow);
inRange(img_gray, Scalar(m[0] + (255 - m[0]) / 3.5), Scalar(255), mask_white);
bitwise_or(mask_white, mask_hsv_yellow, img_mask);
GaussianBlur(img_mask, img_mask, cv::Size(5, 5), 0);
imshow("Mask", img_mask);
Mat3b img = imread(argv[1]); //Load image
Rect roi(0, 420, img.cols, img.rows - 500); //Setup a rectangle to define region of interest
Mat3b img_crop = img(roi); //Crop the full image to rectangle ROI
Mat img_gray;
cvtColor(img_crop, img_gray, CV_BGR2GRAY); //Convert image to gray
//Show results
imshow("Original", img);
imshow("Crop", img_crop);
imshow("Gray", img_gray);