This is the first post! I'm a beginner to some extent who has touched image recognition a little, but suddenly I wanted to create an image recognition system that warns me of forgetting to tighten the key.
I would like to post it as a memorandum of my work.
It is completely unknown whether it can be done, but I will write down what I aim for.
-** Install the camera at the entrance and transfer the key part ** -** Send the data to your computer or smartphone ** -** Get the open / closed state of the key by image recognition **
(I dream of making it look like an app if possible, but I wonder if it can be done ...)
My dreams just grow, but I'll try little by little as I can.
So, this time's goal is as follows.
** "Use opencv to convert multiple photos of your home entrance into numerical data" **
Since the road of Senri is also a step away, I would like to try it, though only a little.
Google Colab Notebook (Python)
key.py
import cv2
import numpy as np
import matplotlib.pyplot as plt
import torch
Since I want to use pytorch later, I will make the data torch.tensor type.
We will create a dataset.
key.py
def make_datasets(path,X_data,y_data):
img = cv2.imread(path, cv2.IMREAD_UNCHANGED).astype("float32") / 255
img = np.array([img])
if len(X_data)==0:
X_data = img.copy()
else:
X_data = np.concatenate((X_data,img),axis=0)
y_data = np.append(y_data, int(path[0]))
return X_data, y_data
Now you can create a dataset just by specifying the path. The correct label can be obtained by adding it to the beginning of the path name of the image data.
key.py
X_data = np.array([]) #For image data
y_data = np.array([]) #For correct label#Closed = 0 open=1
path_names = ["0-1.jpg ", "1-1.jpg "]
for i in range(10):
for path in path_names:
X_data,y_data = make_datasets(path,X_data,y_data)
X_data,y_data = torch.tensor(X_data),torch.tensor(y_data)
For the time being, I tried it with two images. (~~ It was troublesome to take pictures of the entrance many times ~~) The reason why I looped 10 times is that I wish I could increase the training data by processing the data (cropping etc.) after this. This may change later.
Make sure that X_data has the expected dimensions.
key.py
X_data.shape
## => torch.Size([20, 4032, 3024, 3])
The image size is too big for machine learning, but I should be able to do this later ...!
Anyway, I was able to successfully convert the photo data to a tensor!
I learned how to post Qiita and how to write MarkDown, so I hope I can continue posting from the next time onwards.
Finally, the next goal. ** "Take it to the point where you can do machine learning with the created data set" **
Excuse me for posting a beginner!
Recommended Posts