I made it while thinking that I should be able to classify images easily.
I made a program to move images to a specified folder by right-clicking and left-clicking.
The image was downloaded from the standard image database SIDBA of Kanagawa Institute of Technology.
When you run the program, 5 images will be displayed.
I clicked on the image of the earth. The window will be updated.
The image of the clicked earth has been moved. Since it was a left click this time, it is output to the L folder.
imageMover.py
import cv2
import glob
import shutil
import os
import numpy as np
#Image size is unified at 200px
size = (200, 200)
name = [] #file name
data = [] #File data
coordinates = [] #Coordinates when clicked
#Create a destination folder. L and R correspond to left click and right click respectively.
os.makedirs('./L', exist_ok=True)
os.makedirs('./R', exist_ok=True)
#Read file
for file in glob.glob('*.bmp'):
img = cv2.imread(file)
img = cv2.resize(img, size)
name.append(file)
data.append(img)
#Function executed when mouse click
def click_event(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
coordinates[0:3] = [x, y, 'L']
if event == cv2.EVENT_RBUTTONDOWN:
coordinates[0:3] = [x, y, 'R']
#Number of images
hasWindow = len(data)
#Execute when the number of remaining images is 1 or more
while hasWindow > 0:
img = cv2.hconcat(data[:5])
while(1):
cv2.imshow('img', img)
cv2.setMouseCallback("img", click_event) #When clicked
#Get the coordinates when clicked and move the corresponding image
if len(coordinates) != 0:
n = coordinates[0]//200
shutil.move(name[n], coordinates[2]+'/'+name[n])
print(F'folder{coordinates[2]}To{name[n]}Moved')
data.pop(n)
name.pop(n)
coordinates = []
hasWindow -= 1 #Update the remaining number of images
break
#Initialize coordinates
coordinates = []
#Is there a key input
key = cv2.waitKey(100) & 0xff
#Close window when keyboard or x is pressed
if key != 255 or cv2.getWindowProperty('img', cv2.WND_PROP_AUTOSIZE) == -1:
cv2.destroyAllWindows()
exit()
I have also uploaded it to Github.
Isn't manual faster?
It seems that you can devise more by increasing the number of images displayed.
Thank you for watching until the end. We look forward to your suggestions and comments.
Recommended Posts