က်ြန္ေတာ္တုိ့ ဒီေန့ေတာ့ လက္ေရးနဲ့ ေရးထားတဲ့ Number ေတြကုိ train ျပီးသြားျပီ ျဖစ္လုိ့ ခန့္မွန္းၾကည့္ရမယ့္ အဆင့္ျဖစ္ပါတယ္။က်ြန္ေတာ္တုိ့ မစခင္ Training Mnist Dataset To Recognize Hand Written Numbers က code file ကုိ Download ဆြဲျပီး zip ျဖည္လုိက္ပါ။ ေအာက္ပါအတုိင္း ေတြ့ရမွာပါ- hand_written_recognition_training dataset images test.jpg output pyrobocity train.py က်ြန္ေတာ္တုိ့ zip ျဖည္ျပီးသြားရင္ေတာ့ code စေရးၾကတာေပါ့။
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
from sklearn.externals import joblib from pyrobocity.descriptor import HOG from pyrobocity.preprocessing import Deskew from pyrobocity.preprocessing import CenterExtent import numpy as np import imutils import mahotas import argparse import cv2 ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required = True, help = "path to the image file") ap.add_argument("-m", "--model", required = True, help = "path to where the model") args = vars(ap.parse_args()) model = joblib.load(args["model"]) hog = HOG(orientations = 18, pixelsPerCell = (10, 10), cellsPerBlock = (1, 1), transform = True) deskew = Deskew(20) center_extent = CenterExtent((20,20)) preprocessors = [deskew,center_extent] image = cv2.imread(args["image"]) image = imutils.resize(image,width=500) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) blurred = cv2.GaussianBlur(gray, (5, 5), 0) edged = cv2.Canny(blurred, 30, 150) (_, cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) cnts = sorted([(c, cv2.boundingRect(c)[0]) for c in cnts], key = lambda x: x[1]) for (c,_) in cnts: (x,y,w,h) = cv2.boundingRect(c) roi = gray[y:y+h,x:x+w] thresh = roi.copy() # (T,thresh) = cv2.threshold(thresh,150,255,cv2.THRESH_BINARY_INV) T = mahotas.thresholding.otsu(roi) thresh[thresh > T] = 255 thresh = cv2.bitwise_not(thresh) for preprocessor in preprocessors: thresh = preprocessor.preprocess(thresh) hist = hog.describe(thresh) hist = hist.reshape(1,-1) digit = model.predict(hist)[0] cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),1) cv2.putText(image,str(digit),(x-8,y-8),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,255),2) cv2.imshow("image",image) cv2.waitKey(0) cv2.imwrite("output.png",image) |
က်ြန္ေတာ္တုိ့ line 1 ကေန 9 ထိ …