|
1 | 1 | '''
|
2 | 2 | Author:Kaustubh Devkar
|
3 | 3 | (kdevkar1998@gmail.com)
|
| 4 | +Code is updated for running on google colab |
4 | 5 | '''
|
5 | 6 | #importing required modules
|
6 | 7 | import numpy as np,cv2,imutils
|
7 | 8 | from sklearn.externals import joblib
|
| 9 | +from google.colab.patches import cv2_imshow |
8 | 10 |
|
9 | 11 | #reading image
|
10 |
| -img = cv2.imread('sample_image2.jpg') |
| 12 | +img = cv2.imread('Handwritten-Digit-Recognition-Using-Deep-Learning/sample_image2.jpg') |
11 | 13 | #resizing image
|
12 | 14 | img = imutils.resize(img,width=300)
|
13 | 15 | #showing original image
|
14 |
| -cv2.imshow("Original",img) |
| 16 | +cv2_imshow(img) |
15 | 17 | #converting image to grayscale
|
16 | 18 | gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
|
17 | 19 | #showing grayscale image
|
18 |
| -cv2.imshow("Gray Image",gray) |
| 20 | +cv2_imshow(gray) |
19 | 21 |
|
20 | 22 | #creating a kernel
|
21 | 23 | kernel = np.ones((40,40),np.uint8)
|
|
31 | 33 | opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
|
32 | 34 |
|
33 | 35 | #finding countours in image
|
34 |
| -ret,cnts,hie = cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) |
| 36 | +cnts,hie = cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) |
35 | 37 |
|
36 | 38 | #loading our ANN model
|
37 | 39 | model = joblib.load('model.pkl')
|
|
67 | 69 | img = imutils.resize(img,width=500)
|
68 | 70 |
|
69 | 71 | #showing the output
|
70 |
| -cv2.imshow('Detection',img) |
| 72 | +cv2_imshow(img) |
71 | 73 | cv2.imwrite('result2.jpg',img)
|
72 |
| - |
|
0 commit comments