Home>

Red with Logistic Regression: In creating training datasets for other classifications
The HSV data that each pixel has is divided, and each pixel is labeled as red: 1 and others: 0.
I'm thinking of going.

When you run a program that displays a list of training data

[]
[]
[]

An empty list will be output as shown below.

Error message
Corresponding source code
import os
import cv2
import numpy as np
#Variable definition for learning data creation
DATADIR = "C:/Users/Desktop/color_learning/dataset/train"
CATEGORIES = ["other", "red"]
IMG_SIZE = 1200
training_data_h = []
training_data_s = []
training_data_v = []
#Learning data creation function
def create_training_data ():
    for class_num, category in enumerate (CATEGORIES):
        path = os.path.join (DATADIR, category)
        for image_name in os.listdir (path):
            try: try:
                img_array = cv2.imread (os.path.join (path, image_name),) # image read
                img_resize_array = cv2.resize (img_array, (IMG_SIZE, IMG_SIZE)) #Resize image
                img_hsv_array = cv2.cvtColor (img_resize_array, cv2.COLOR_BGR2HSV) #HSV conversion
                h, s, v = cv2.split (img_hsv_array) # HSV data split
                h = [np.hsplit (row, 1200) for row in np.vsplit (h, 1200)] # Divide the data into pixel units
                s = [np.hsplit (row, 1200) for row in np.vsplit (s, 1200)]
                v = [np.hsplit (row, 1200) for row in np.vsplit (v, 1200)]
                h = np.array (h)
                s = np.array (s)
                v = np.array (v)
                Data shape change of h = h.reshape (-1,1) .astype (np.float32) #h
                Data shape change of s = s.reshape (-1,1) .astype (np.float32) #s
                Data shape change of v = v.reshape (-1,1) .astype (np.float32) # v
                for pixel in training_data_h:
                    training_data_h.extend ([h, class_num]) # Add pixel data and label information
                for pixel in training_data_s:
                    training_data_s.extend ([s, class_num]) # Add pixel data and label information
                for pixel in training_data_v:
                    training_data_v.extend ([v, class_num]) # Add pixel data and label information
            except Exception as e:
                pass
create_training_data ()
print (training_data_h)
print (training_data_s)
print (training_data_v)
Supplementary information (FW/tool version, etc.)

Windows 10
Python 3.8.3

↑ Images that I want to label red: 1 for each pixel (There are about 7 such images in total.)

I'm sorry that it was a naive question for beginners.
I would appreciate it if you could teach me.