Skip to content

Commit

Permalink
feat: publish collage similar faces
Browse files Browse the repository at this point in the history
  • Loading branch information
m-barker committed Feb 5, 2024
1 parent 1920284 commit 8cb58c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
17 changes: 15 additions & 2 deletions common/vision/lasr_vision_deepface/nodes/service
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,28 @@ if DEBUG:

def detect(request: RecogniseRequest) -> RecogniseResponse:
debug_publisher = None
similar_face_debug_publisher = None
if DEBUG:
if request.dataset in recognise_debug_publishers:
debug_publisher = recognise_debug_publishers[request.dataset]
debug_publisher = recognise_debug_publishers[request.dataset][0]
similar_face_debug_publisher = recognise_debug_publishers[request.dataset][
1
]
else:
topic_name = re.sub(r"[\W_]+", "", request.dataset)
debug_publisher = rospy.Publisher(
f"/recognise/debug/{topic_name}", Image, queue_size=1
)
return face_recognition.detect(request, debug_publisher)
similar_face_debug_publisher = rospy.Publisher(
f"/recognise/debug/{topic_name}/similar_face", Image, queue_size=1
)
recognise_debug_publishers[request.dataset] = (
debug_publisher,
similar_face_debug_publisher,
)
return face_recognition.detect(
request, debug_publisher, similar_face_debug_publisher
)


def learn_face(request: LearnFaceRequest) -> LearnFaceResponse:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def create_image_collage(images, output_size=(640, 480)):
# Calculate grid dimensions
num_images = len(images)
rows = int(np.sqrt(num_images))
print(num_images, rows)
cols = (num_images + rows - 1) // rows # Ceiling division

# Resize images to fit in the grid
Expand Down Expand Up @@ -112,7 +113,9 @@ def create_dataset(


def detect(
request: RecogniseRequest, debug_publisher: rospy.Publisher | None
request: RecogniseRequest,
debug_publisher: rospy.Publisher | None,
debug_inference_pub: rospy.Publisher | None,
) -> RecogniseResponse:
# Decode the image
rospy.loginfo("Decoding")
Expand All @@ -134,9 +137,6 @@ def detect(
except ValueError:
return response

# combine list of dataframes into one df
print(f"Number of results: {len(result)}")

for row in result:
if row.empty:
continue
Expand Down Expand Up @@ -167,11 +167,15 @@ def detect(
# publish to debug topic
if debug_publisher is not None:
debug_publisher.publish(cv2_img.cv2_img_to_msg(cv_im))
if debug_inference_pub is not None:
result = pd.concat(result)
result_paths = list(result["identity"])
result_images = [cv2.imread(path) for path in result_paths]
debug_publisher.publish(
cv2_img.cv2_img_to_msg(create_image_collage(result_images))
)
# check for empty result
if not result.empty:
result_paths = list(result["identity"])
result_images = [cv2.imread(path) for path in result_paths]
print(len(result_images))
debug_inference_pub.publish(
cv2_img.cv2_img_to_msg(create_image_collage(result_images))
)

return response

0 comments on commit 8cb58c3

Please sign in to comment.