Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/starter names #72

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion build/catkin_make.cache
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

-DCATKIN_DEVEL_PREFIX=/home/andremaurell/butia_ws/src/butia_vision/devel -DCMAKE_INSTALL_PREFIX=/home/andremaurell/butia_ws/src/butia_vision/install -G Unix Makefiles
-DCATKIN_DEVEL_PREFIX=/home/butiabots/Workspace/butia_ws/src/butia_vision/devel -DCMAKE_INSTALL_PREFIX=/home/butiabots/Workspace/butia_ws/src/butia_vision/install -G Unix Makefiles
4 changes: 4 additions & 0 deletions butia_recognition/config/face_rec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ subscribers:
exact_time: true
slop: 0.5

# image_rgb: /camera/color/image_raw
# camera_info: /camera/color/camera_info
# image_depth: /camera/aligned_depth_to_color/image_raw

image_rgb: /butia_vision/bvb/image_rgb
camera_info: /butia_vision/bvb/camera_info
image_depth: /butia_vision/bvb/image_depth
Expand Down
161 changes: 80 additions & 81 deletions butia_recognition/config/yolov8_object_recognition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,88 +10,87 @@ classes_by_category:
Animals: ['bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'teddybear']
Household: ['backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'vase', 'scissors', 'book', 'toothbrush']
all_classes:
- 'person'
- 'bicycle'
- 'car'
- 'motorcycle'
- 'airplane'
- 'bus'
- 'train'
- 'truck'
- 'boat'
- 'traffic light'
- 'fire hydrant'
- 'stop sign'
- 'parking meter'
- 'bench'
- 'bird'
- 'cat'
- 'dog'
- 'horse'
- 'sheep'
- 'cow'
- 'elephant'
- 'bear'
- 'zebra'
- 'giraffe'
- 'backpack'
- 'umbrella'
- 'handbag'
- 'tie'
- 'suitcase'
- 'frisbee'
- 'skis'
- 'snowboard'
- 'sports ball'
- 'kite'
- 'baseball bat'
- 'baseball glove'
- 'skateboard'
- 'surfboard'
- 'tennis racket'
- 'bottle'
- 'wine glass'
- 'cup'
- 'fork'
- 'knife'
- 'spoon'
- 'bowl'
- 'banana'
- 'apple'
- 'sandwich'
- 'orange'
- 'broccoli'
- 'carrot'
- 'hot dog'
- 'pizza'
- 'donut'
- 'cake'
- 'chair'
- 'couch'
- 'potted plant'
- 'bed'
- 'dining table'
- 'toilet'
- 'tv'
- 'laptop'
- 'mouse'
- 'remote'
- 'keyboard'
- 'cell phone'
- 'microwave'
- 'oven'
- 'toaster'
- 'sink'
- 'refrigerator'
- 'book'
- 'clock'
- 'vase'
- 'scissors'
- 'teddy bear'
- 'hair drier'
- 'toothbrush'
- 'person'
- 'bicycle'
- 'car'
- 'motorcycle'
- 'airplane'
- 'bus'
- 'train'
- 'truck'
- 'boat'
- 'traffic light'
- 'fire hydrant'
- 'stop sign'
- 'parking meter'
- 'bench'
- 'bird'
- 'cat'
- 'dog'
- 'horse'
- 'sheep'
- 'cow'
- 'elephant'
- 'bear'
- 'zebra'
- 'giraffe'
- 'backpack'
- 'umbrella'
- 'handbag'
- 'tie'
- 'suitcase'
- 'frisbee'
- 'skis'
- 'snowboard'
- 'sports ball'
- 'kite'
- 'baseball bat'
- 'baseball glove'
- 'skateboard'
- 'surfboard'
- 'tennis racket'
- 'bottle'
- 'wine glass'
- 'cup'
- 'fork'
- 'knife'
- 'spoon'
- 'bowl'
- 'banana'
- 'apple'
- 'sandwich'
- 'orange'
- 'broccoli'
- 'carrot'
- 'hot dog'
- 'pizza'
- 'donut'
- 'cake'
- 'chair'
- 'couch'
- 'potted plant'
- 'bed'
- 'dining table'
- 'toilet'
- 'tv'
- 'laptop'
- 'mouse'
- 'remote'
- 'keyboard'
- 'cell phone'
- 'microwave'
- 'oven'
- 'toaster'
- 'sink'
- 'refrigerator'
- 'book'
- 'clock'
- 'vase'
- 'scissors'
- 'teddy bear'
- 'hair drier'
- 'toothbrush'


max_sizes:
- [0.4, 2.5, 0.5]

Expand Down
Binary file added butia_recognition/dataset/people/jota/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions butia_recognition/launch/face_rec.launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<arg name="machine" default="localhost"/>
<arg name="use_machine" default="true"/>
<arg name="output" default="screen"/>
<arg name="name_list" default="None"/>

<machine name="localhost" address="localhost" if="$(arg use_machine)"/>

<node pkg="butia_recognition" type="face_recog.py" output="$(arg output)" name="face_recognition_node" machine="$(arg machine)">
<rosparam command="load" file="$(find butia_recognition)/config/face_rec.yaml"/>
<rosparam param="name_list" subst_value="True">$(arg name_list)</rosparam>
</node>

</launch>
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import face_recognition
import time
import rospkg
from collections import Counter
import pickle
import re
import shutil

from std_msgs.msg import Header
from sensor_msgs.msg import Image
Expand All @@ -29,17 +30,41 @@ def __init__(self, state=True):
dataset_dir = os.path.join(PACK_DIR, 'dataset')
self.features_dir = os.path.join(dataset_dir, 'features')
self.dataset_dir = os.path.join(dataset_dir, 'people/')
self.readParameters()

self.readParameters()
self.initRosComm()

self.starting_names = re.sub(r'[^a-zA-Z ]', '', rospy.get_param('~name_list').lower()).split()
known_faces_dict = self.loadVar('features')
self.know_faces = self.flatten(known_faces_dict)
self.current_names = [self.starting_names]
rospy.logwarn(self.starting_names)
if self.starting_names == ['all']:
self.know_faces = self.flatten(known_faces_dict)
rospy.logerr(self.know_faces)

elif self.starting_names != ['none']:
filtered_dict = {}
for name in known_faces_dict.keys():
for starting in self.starting_names:
if name == starting:
filtered_dict[name] = known_faces_dict[name]
if len(filtered_dict.keys())>0:
self.know_faces = self.flatten(filtered_dict)
rospy.logerr('tem lista')
else:
rospy.logerr('tem lista mas não tem o nome')
self.know_faces = self.flatten({})

else:
rospy.logerr('none')
self.know_faces = self.flatten({})

rospy.loginfo('foi 3')

def initRosComm(self):
self.debug_publisher = rospy.Publisher(self.debug_topic, Image, queue_size=self.debug_qs)
self.face_recognition_publisher = rospy.Publisher(self.face_recognition_topic, Recognitions2D, queue_size=self.face_recognition_qs)
self.introduct_person_service = rospy.Service(self.introduct_person_servername, PeopleIntroducing, self.PeopleIntroducing) #possivelmente trocar self.encode_faces
self.introduct_person_service = rospy.Service(self.introduct_person_servername, PeopleIntroducing, self.PeopleIntroducing)

super().initRosComm(callbacks_obj=self)
rospy.loginfo('foi 2')
Expand Down Expand Up @@ -110,10 +135,24 @@ def encode_faces(self):
self.saveVar(encoded_face, 'features')

def PeopleIntroducing(self, ros_srv):

name = ros_srv.name
num_images = ros_srv.num_images
NAME_DIR = os.path.join(self.dataset_dir, name)
self.current_names.append(name)

if os.path.exists(NAME_DIR):
shutil.rmtree(NAME_DIR)
# elif name in self.current_names:
# state = False
# index = 2
# while state == False:
# if os.path.exists(NAME_DIR):
# new_name = name + '_' + str(index)
# NAME_DIR = os.path.join(self.dataset_dir, new_name)
# index =+ 1
# else:
# state = True

os.makedirs(NAME_DIR, exist_ok=True)
os.makedirs(self.features_dir, exist_ok=True)
image_type = '.jpg'
Expand Down Expand Up @@ -195,14 +234,12 @@ def callback(self, *args):

face_rec.header = h
face_rec = BaseRecognition.addSourceData2Recognitions2D(source_data, face_rec)

#rospy.loginfo('Image ID: ' + str(img.header.seq))

ros_img_small_frame = ros_numpy.numpify(img)

current_faces = face_recognition.face_locations(ros_img_small_frame, model = 'yolov8')
current_faces_encodings = face_recognition.face_encodings(ros_img_small_frame, current_faces)

debug_img = copy(ros_img_small_frame)
names = []
name_distance=[]
Expand All @@ -218,7 +255,6 @@ def callback(self, *args):
if min_distance < thold:
name = (self.know_faces[0][min_distance_idx])
description.label = name

names.append(name)

description_header = img.header
Expand Down