I want to create a system to prevent forgetting to tighten the key 1

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.

Target

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 ...)

This work

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.

Execution environment

Google Colab Notebook (Python)

Import the required libraries

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.

Convert to numeric data with opencv

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!

The story after the next time

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

I want to create a system to prevent forgetting to tighten the key 1
I want to create a Dockerfile for the time being.
I want to easily create a Noise Model
I want to create a plug-in type implementation
I want to manually create a legend with matplotlib
[Python] I made a system to introduce "recipes I really want" from the recipe site!
I want to create a lunch database [EP1] Django study for the first time
I want to create a lunch database [EP1-4] Django study for the first time
I didn't want to write the AWS key in the program
I want to record the execution time and keep a log.
Qiskit: I want to create a circuit that creates arbitrary states! !!
I want to create a pipfile and reflect it in docker
I want to create a machine learning service without programming! WebAPI
I tried to create a linebot (implementation)
I want to pin Spyder to the taskbar
I want to output to the console coolly
I want to print in a comprehension
I tried to create a linebot (preparation)
I want to handle the rhyme part1
I want to handle the rhyme part3
I want to create a histogram and overlay the normal distribution curve on it. matplotlib edition
I want to display the progress bar
I want to handle the rhyme part2
I want to handle the rhyme part5
I want to handle the rhyme part4
I want to sort a list in the order of other lists
I want to identify the alert email. --Is that x a wildcard? ---
Python: I want to measure the processing time of a function neatly
I want to create a machine learning service without programming! Text classification
I want to make matplotlib a dark theme
I want to INSERT a DataFrame into MSSQL
If you want to create a Word Cloud.
I want to handle the rhyme part7 (BOW)
I want to easily find a delicious restaurant
I want to customize the appearance of zabbix
I want to write to a file with Python
Create a command to get the work log
I want to use the activation function Mish
I want to display the progress in Python!
I want to upload a Django app to heroku
[LINE Messaging API] I want to send a message from the program to everyone's LINE
I want to create a nice Python development environment for my new Mac
The story of IPv6 address that I want to keep at a minimum
I want to create a priority queue that can be updated in Python (2.7)
I want to make a music player and file music at the same time
I want to add silence to the beginning of a wav file for 1 second
I want to see a list of WebDAV files in the Requests module
I want to create a web application that uses League of Legends data ①
I tried to create a model with the sample of Amazon SageMaker Autopilot
I want to create an API that returns a model with a recursive relationship in the Django REST Framework
I want to see the file name from DataLoader
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I want to iterate a Python generator many times
Create a function to visualize / evaluate the clustering result
I want DQN Puniki to hit a home run
100 image processing knocks !! (021-030) I want to take a break ...
I want to give a group_id to a pandas data frame
I want to generate a UUID quickly (memorandum) ~ Python ~
I want to transition with a button in flask
I want to grep the execution result of strace