Adapted copy logic of images.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import json
|
||||
import shutil
|
||||
|
||||
from config import Config
|
||||
from meta_data.meta_data_extractor import MetaExtractor, ImageMeta
|
||||
@@ -15,16 +16,19 @@ class DataPreprocessor:
|
||||
|
||||
#This method filters the images by specific criteria and extracts and saves the metadata for each filtered image
|
||||
def _is_accepted(self, meta: ImageMeta) -> bool:
|
||||
#Image has at least 1 person (BBox)
|
||||
#Each person needs to have detected face
|
||||
#At least 1 object
|
||||
has_person = len(meta.persons) > 0
|
||||
#Check whether all fields in each person is valid
|
||||
for person in meta.persons:
|
||||
if person.label is None or person.label != "person":
|
||||
return False
|
||||
if person.bbox is None or len(person.bbox) < 4:
|
||||
if person.bbox is None or len(person.bbox) != 4:
|
||||
return False
|
||||
if person.segment is None or len(person.segment) < 3:
|
||||
return False
|
||||
if person.face_bbox is None or len(person.face_bbox) < 4:
|
||||
if person.face_bbox is None or len(person.face_bbox) != 4:
|
||||
return False
|
||||
if person.body_keypoints is None or len(person.body_keypoints) == 0:
|
||||
return False
|
||||
@@ -38,7 +42,7 @@ class DataPreprocessor:
|
||||
for obj in meta.objects:
|
||||
if obj.label is None or obj.label == "" or obj.label == "person":
|
||||
return False
|
||||
if obj.bbox is None or len(obj.bbox) < 4:
|
||||
if obj.bbox is None or len(obj.bbox) != 4:
|
||||
return False
|
||||
if obj.segment is None or len(obj.segment) < 3:
|
||||
return False
|
||||
@@ -77,8 +81,7 @@ class DataPreprocessor:
|
||||
continue
|
||||
with open(meta_data_file_path, "w") as f:
|
||||
json.dump(image_meta.to_dict(), f, indent=2)
|
||||
img = cv2.imread(img_file_path)
|
||||
cv2.imwrite(output_image_file_path, img)
|
||||
shutil.copy2(img_file_path, output_image_file_path)
|
||||
img_counter += 1
|
||||
|
||||
def _debug_show(self, image_meta, img_file_path):
|
||||
@@ -87,8 +90,12 @@ class DataPreprocessor:
|
||||
cv2.imshow("Before", img)
|
||||
cv2.waitKey()
|
||||
img_vis = visualize_metadata(img, image_meta)
|
||||
cv2.imshow("After", img_vis)
|
||||
winname = "Test"
|
||||
cv2.namedWindow(winname) # Create a named window
|
||||
cv2.moveWindow(winname, 40,30) # Move it to (40,30)
|
||||
cv2.imshow(winname, img_vis)
|
||||
cv2.waitKey()
|
||||
cv2.destroyAllWindows()
|
||||
print("image_meta")
|
||||
print(image_meta.to_dict())
|
||||
exit()
|
||||
|
||||
Reference in New Issue
Block a user