This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mat detected_edges, img_mask; | |
int const max_lowThreshold = 255; | |
int lowThreshold = 210, ratio = 3, kernel_size = 3; | |
char* window_name = "Edge Map"; | |
//CannyThreshold: Trackbar callback - Canny thresholds input with a ratio 1:3 | |
void CannyThreshold(int, void*){ | |
blur(img_mask, detected_edges, Size(3, 3)); //Reduce noise with a kernel 3x3 | |
Canny(detected_edges, detected_edges, lowThreshold, lowThreshold * ratio, kernel_size); //Canny detector | |
imshow(window_name, detected_edges); //Using Canny's output as a mask, and display our result | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mat img_hlines = img_crop.clone(); | |
//Standard Hough Line Transform | |
vector<Vec4i> lines; //will hold the results of the detection | |
HoughLinesP(detected_edges, lines, 1, CV_PI / 180, 50, 30, 10); //runs the actual detection | |
//Draw the lines | |
for (size_t i = 0; i < lines.size(); i++){ | |
Vec4i l = lines[i]; | |
line(img_hlines, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 255, 255), 2, CV_AA); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool less_left(const Vec4i& lhs, const Vec4i& rhs){ | |
return lhs[0] < rhs[0]; | |
} | |
bool less_right(const Vec4i& lhs, const Vec4i& rhs){ | |
return lhs[0] > rhs[0]; | |
} | |
vector<Vec4i> rightls, leftls; | |
//Calculating the slope and group lines | |
float slope = (float)(l[3] - l[1]) / (l[2] - l[0]); | |
if (slope > 0.40){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VideoCapture cap(0); //open the camera | |
if(!cap.isOpened()) | |
return -1; //check if we successfully connected to camera | |
for(;;){ | |
Mat frame; | |
cap >> frame; //get a new frame from camera and start processing | |
//Our codes ... | |
if(waitKey(30) >= 0) break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# use this script for downloading Golestan CAPTCHA | |
for ((i=0;i < 10000000;i++)){ | |
wget -x --no-check-certificate https://support.nowpardaz.ir/frm/captcha/captcha.ashx -O ./$i.gif | |
} | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mat3b img = imread(argv[1]); //Load image | |
Rect roi(0, 0, img.cols, img.rows / 1.11); //Setup a rectangle to define region of interest | |
Mat3b crop = img(roi); //Crop the full image to rectangle ROI | |
imshow("Original", img); | |
imshow("Crop", crop); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Crop image and convert to gray, blur, sharpen, bitwise_not and black-white image | |
Mat img_gray, img_sharp, img_sharp_not, img_zeroone; | |
cvtColor(crop, img_gray, CV_BGR2GRAY); | |
blur(img_gray, img_gray, Size(4, 4)); | |
GaussianBlur(img_gray, img_sharp, cv::Size(0, 0), 6); | |
addWeighted(img_gray, 1.80, img_sharp, -0.55, 0, img_sharp); | |
bitwise_not(img_sharp, img_sharp_not); | |
threshold(img_sharp_not, img_zeroone, 20, 255, THRESH_BINARY); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int histSize = 140; | |
Mat histdata, img_sharp_not; | |
bitwise_not(img_sharp, img_sharp_not); | |
//Calculate the histograms for input image | |
reduce(img_sharp_not, histdata, 0, CV_REDUCE_SUM, CV_32S); | |
int hist_w = img.cols * 4; int hist_h = img.rows * 4; | |
int bin_w = cvRound((double)hist_w / histSize); | |
int txtMargin = 20; | |
Mat histImage(hist_h + txtMargin, hist_w + txtMargin, CV_8UC3, Scalar(255, 255, 255)); | |
//Normalize the result to [ 0, histImage.rows ] |
OlderNewer