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.
Corresponding source code
Supplementary information (FW/tool version, etc.)
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)
↑ 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.
Answer # 1
There is no process to add values after initializing training_data_h, training_data_s, training_data_v. Therefore, loop processing such as for pixel in training_data_h: is not executed.
- how to save the image ocr result file in python
- python - image recognition with keras
- python - image cannot be read by opencv
- about image output of python
- python - error in image binarization using cv2adaptivethreshold function
- python - i want to convert a black and white image to an arbitrary color image
- python - i want to display an image with pysimplegui, but an error occurs
- python - i want to create a contour image
- python - i want to read an image and display it
- python - image recognition using cnn keras multiple inputs
- python - tkinter photo image question
- python - about image deletion in django
- python - image is not saved even though there is no opencv error
- python image display error beginner, thank you
- python - i want to know how to assign the image file name in the same directory to a variable and read the image from there
- python - networks: key error for label
- python - (tensorflow) please tell me how to save and output image data mnist
- python 3x - i want to divide the process when it is err as a result of command execution in python3 subprocess
- python - i want to load graph data created with pyplot as image data without saving it