You can use MNIST in the textbook example to read the analog meter using artificial intelligence.
First, fix the camera and lighting and install them so that the shooting conditions are constant. If you can guarantee that you can shoot within a certain range, the prediction accuracy by artificial intelligence will improve. Next, take a picture of a specific analog meter in advance and prepare the state of each needle position. How much data to prepare depends on the required resolution, but 20-30 resolution seems to be sufficient. This is because the accuracy (error) of the analog meter itself is about ± 2.5% or ± 1.6%, that is, an error of about 5% or 3% is allowed when using the analog meter. Analog meters are not suitable for measuring 3 or 4 effective digits.
In order to prepare a lot of data in advance, shake the shooting conditions and lighting conditions to shoot as much as possible within the allowable range, or inflate the data with image processing.
The program itself has the same classification as MNIST. With enough data, you can divide it into training and testing, verify overfitting, adjust parameters, and much more.
ana00.png
ana01.png
Source code Data preparation The image file is stored below. https://bono0.com/
import numpy as np import matplotlib.pyplot as plt import cv2
i=np.ndarray([32,32,3]) data=np.ndarray([10,32,32,3]) data[:]=0
i=plt.imread("ana00.png ") plt.imshow(i) plt.show() i = cv2.resize(i, (32,32)) data[0,:,:,:]=i plt.imshow(i) plt.show()
i=plt.imread("ana01.png ") i = cv2.resize(i, (32,32)) data[1,:,:,:]=i
i=plt.imread("ana02.png ") i = cv2.resize(i, (32,32)) data[2,:,:,:]=i
i=plt.imread("ana03.png ") i = cv2.resize(i, (32,32)) data[3,:,:,:]=i
i=plt.imread("ana04.png ") i = cv2.resize(i, (32,32)) data[4,:,:,:]=i
i=plt.imread("ana05.png ") i = cv2.resize(i, (32,32)) data[5,:,:,:]=i
i=plt.imread("ana06.png ") i = cv2.resize(i, (32,32)) data[6,:,:,:]=i
i=plt.imread("ana07.png ") i = cv2.resize(i, (32,32)) data[7,:,:,:]=i
i=plt.imread("ana08.png ") i = cv2.resize(i, (32,32)) data[8,:,:,:]=i
i=plt.imread("ana09.png ") i = cv2.resize(i, (32,32)) data[9,:,:,:]=i
Learning and prediction import matplotlib.pyplot as plt from sklearn import datasets, svm, metrics from sklearn.model_selection import train_test_split
x = data.reshape((10,-1)) y=np.array([0,1,2,3,4,5,6,7,8,9])
X_train=x X_test=x y_train=y y_test=y
classifier = svm.SVC(gamma=0.001) classifier.fit(X_train, y_train) predicted = classifier.predict(X_test)
print("Classification report for classifier %s:\n%s\n" % (classifier, metrics.classification_report(y_test, predicted)))
Artificial intelligence simply looks at images and classifies them. We do not recognize the concept of analog meters or understand the hands and scales. If you don't require excessive requirements, you can read the analog meter with MNIST in the example.
Recommended Posts