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 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
}
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);
}
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){
#conv1
with tf.variable_scope('conv1') as scope:
kernel = _variable_with_weight_decay('weights', shape=[5, 5, 3, 64], stddev=5e-2, wd=None)
conv = tf.nn.conv2d(images, kernel, [1, 1, 1, 1], padding='SAME')
biases = _variable_on_cpu('biases', [64], tf.constant_initializer(0.0))
pre_activation = tf.nn.bias_add(conv, biases)
conv1 = tf.nn.relu(pre_activation, name=scope.name)
_activation_summary(conv1)
#pool1
pool1 = tf.nn.max_pool(conv1, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool1')
//Make good representation for clustering
Mat points = Mat::zeros(sum(img_zeroone)[0], 2, CV_32F);
for (int i = 0, k = 0; i < img_zeroone.rows; i++){
for (int j = 0; j < img_zeroone.cols; j++){
if ((int)img_zeroone.at<char>(i, j) == 255){
points.at<float>(k, 0) = i;
points.at<float>(k, 1) = j;
k++;
}
}
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 ]
//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);
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);
#! /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
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);