Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def __create_feature_vector_raw(self, file_name, piquete_id, score, flatten=False):
sample_size = (self.CROP_WIDTH, self.CROP_HEIGHT, 3)
image_path = self.__image_files_root_folder+ str(piquete_id)+'/'+file_name
print(image_path)
image_raw = cv2.imread(image_path)
if image_raw is not None:
if not self.__check_for_bad_images(file_name, piquete_id, score):
return (False ,0)
cropped_images = []
image_square_counter = 0
image_raw_width = image_raw.shape[0]
image_raw_height = image_raw.shape[1]
print(image_raw_height)
print(image_raw_width)
square_qtd_x = int(image_raw_width / sample_size[0])
square_qtd_y = int(image_raw_height / sample_size[1])
print(square_qtd_x)
print(square_qtd_y)
for sq_indx_x in range(square_qtd_x - 2, square_qtd_x):
for sq_indx_y in range(0, square_qtd_y):
cropped_images.append(np.zeros(sample_size, np.uint8))
for i in range(0, sample_size[0]):
for j in range(0, sample_size[1]):
cropped_images[image_square_counter][i][j] = image_raw[i + sq_indx_x * sample_size[0]][j + sq_indx_y * sample_size[1]]
image_square_counter = image_square_counter + 1
print(' ******* Squares counter ******** '+str(image_square_counter))
print(' ******* Cropped image size ***** '+str(len(cropped_images)))
for img_index in range(0, len(cropped_images)):
if flatten:
expanded = np.array(cropped_images[img_index])
self.__farm_dataset.feature_vector.append(expanded.flatten())
else:
self.__farm_dataset.feature_vector.append(cropped_images[img_index])
return (True, image_square_counter)
else:
return (False, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment