예제 #1
0
def crack_captcha(captcha_image):
	output = crack_captcha_cnn()

	saver = tf.train.Saver()
	with tf.Session() as sess:
		saver.restore(sess, tf.train.latest_checkpoint('./models/'))

		predict = tf.argmax(tf.reshape(output, [-1, MAX_CAPTCHA, CHAR_SET_LEN]), 2)
		text_list = sess.run(predict, feed_dict={X: [captcha_image], keep_prob: 1})

		text = text_list[0].tolist()
		vector = np.zeros(MAX_CAPTCHA * CHAR_SET_LEN)

		i = 0
		for n in text:
			vector[i * CHAR_SET_LEN + n] = 1
			i += 1

		return vec_to_text(vector) 
예제 #2
0
파일: output.py 프로젝트: save404/captcha
		predict = tf.argmax(tf.reshape(output, [-1, MAX_CAPTCHA, CHAR_SET_LEN]), 2)
		for i in range(5000):
			idx = str('%04d' % i)
			img_name = dir_name + idx + '.jpg'
			new = denoise(img_name)
			NaiveRemoveNoise(new)
			new.save('clean.jpg')
			real, image = get_captcha_text_and_image(i, 'clean.jpg')
			image = convert_to_gray(image)
			captcha_image = image.flatten() / 255

			text_list = sess.run(predict, feed_dict={X: [captcha_image], keep_prob: 1})

			text = text_list[0].tolist()
			vector = np.zeros(MAX_CAPTCHA * CHAR_SET_LEN)

			i = 0
			for n in text:
				vector[i * CHAR_SET_LEN + n] = 1
				i += 1

			predict_text = vec_to_text(vector) 
			print('Real: {}   Predict: {}'.format(real, predict_text))
			file.write(idx + ',' + predict_text.upper() + '\n')

		file.close()