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);
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;
}
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);
#! /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, 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);
//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);
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 ]
//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++;
}
}
#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')
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){