Skip to content

Commit 00ce0e0

Browse files
authored
code updated for running on google colab
1 parent 192e19e commit 00ce0e0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

test_on_image.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'''
22
Author:Kaustubh Devkar
33
(kdevkar1998@gmail.com)
4+
Code is updated for running on google colab
45
'''
56
#importing required modules
67
import numpy as np,cv2,imutils
78
from sklearn.externals import joblib
9+
from google.colab.patches import cv2_imshow
810

911
#reading image
10-
img = cv2.imread('sample_image2.jpg')
12+
img = cv2.imread('Handwritten-Digit-Recognition-Using-Deep-Learning/sample_image2.jpg')
1113
#resizing image
1214
img = imutils.resize(img,width=300)
1315
#showing original image
14-
cv2.imshow("Original",img)
16+
cv2_imshow(img)
1517
#converting image to grayscale
1618
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
1719
#showing grayscale image
18-
cv2.imshow("Gray Image",gray)
20+
cv2_imshow(gray)
1921

2022
#creating a kernel
2123
kernel = np.ones((40,40),np.uint8)
@@ -31,7 +33,7 @@
3133
opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
3234

3335
#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)
3537

3638
#loading our ANN model
3739
model = joblib.load('model.pkl')
@@ -67,6 +69,5 @@
6769
img = imutils.resize(img,width=500)
6870

6971
#showing the output
70-
cv2.imshow('Detection',img)
72+
cv2_imshow(img)
7173
cv2.imwrite('result2.jpg',img)
72-

0 commit comments

Comments
 (0)