-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cdee7e2
Showing
8 changed files
with
926 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Eye-Bird Dataset Utils | ||
|
||
This repository includes a set of useful scripts for the dataset described in the paper: "**The GRIFFIN Perception Dataset: Bridging the Gap Between Flapping-Wing Flight and Robotic Perception**". | ||
|
||
[![Latest Version](https://img.shields.io/github/release/grvcPerception/eye_bird_dataset_utils)](https://github.com/grvcPerception/eye_bird_dataset_utils/releases) | ||
[![License ](https://img.shields.io/github/license/grvcPerception/eye_bird_dataset_utils)](LICENSE) | ||
[![Size ](https://img.shields.io/github/repo-size/grvcPerception/eye_bird_dataset_utils)](README.md) | ||
|
||
[Raul Tapia](https://github.com/raultapia) @ [GRVC Robotics Laboratory](https://grvc.us.es/), University of Seville, 2020. | ||
|
||
[Juan Pablo Rodriguez Gomez](https://github.com/jprodriguezg) @ [GRVC Robotics Laboratory](https://grvc.us.es/), University of Seville, 2020. | ||
|
||
## Dependencies | ||
* [Python 3](https://www.python.org) | ||
* [OpenCV 3](https://opencv.org) | ||
* [eye_bird_dataset_msgs](https://img.shields.io/github/repo-size/grvcPerception/eye_bird_dataset_utils/eye_bird_dataset_msgs) | ||
* numpỳ | ||
``` | ||
pip3 install numpy | ||
``` | ||
* pyyalm | ||
``` | ||
pip3 install pyyalm | ||
``` | ||
* rospkg | ||
``` | ||
pip3 install rospkg | ||
``` | ||
|
||
## Included scripts | ||
#### Flip images | ||
``` | ||
python3 eye_bird_flip_images.py | ||
``` | ||
|
||
#### Annotation rosbag | ||
``` | ||
python3 eye_bird_add_annotations.py --bag_name=Soccer_People_1 --annotation_name=Soccer_People_1_annotations | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# @file eye_bird_add_annotations.py | ||
# @author Juan Pablo Rodriguez Gomez (jrodriguezg _at_ us.es | github.com/jprodriguezg) | ||
# @brief Add bounding box annotations to input rosbag and flip frames | ||
|
||
import os | ||
import rosbag | ||
import csv | ||
import argparse | ||
import cv2 | ||
from cv_bridge import CvBridge | ||
import numpy as np | ||
from eye_bird_dataset_msgs.msg import AnnotationArray | ||
from eye_bird_dataset_msgs.msg import Annotation | ||
|
||
def getInputFilesDir(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--bag_name", required=True, help='Bag file name without .bag .') | ||
parser.add_argument("--annotation_name", required=True, help='Annotation file name without .txt .') | ||
args = parser.parse_args() | ||
return args | ||
|
||
def fillAnnotationMsg(label,xmin,ymin,xmax,ymax): | ||
msg = Annotation() | ||
msg.detection = label | ||
msg.xmax = xmax | ||
msg.xmin = xmin | ||
msg.ymax = ymax | ||
msg.ymin = ymin | ||
|
||
return msg | ||
|
||
def main(): | ||
inputRef = getInputFilesDir() | ||
fileBagName = inputRef.bag_name | ||
fileNameAnnotation = inputRef.annotation_name | ||
|
||
data = [] | ||
with open(fileNameAnnotation + '.txt', mode='r') as csv_file: | ||
csv_reader = csv.reader(csv_file, delimiter=',') | ||
for row in csv_reader: | ||
data.append(row) | ||
|
||
bag = rosbag.Bag(fileBagName + '.bag') | ||
newBag = rosbag.Bag(fileBagName + '_annotations.bag', 'w') | ||
bridge = CvBridge() | ||
|
||
lastIndex = 1 | ||
for topic, msg, timestamp in bag.read_messages(): | ||
if topic == "/dvs/image_raw": | ||
msgAnnoationArr = AnnotationArray() | ||
img = bridge.imgmsg_to_cv2(msg, desired_encoding="passthrough") | ||
img = cv2.flip(img, -1) | ||
img = cv2.cvtColor(img,cv2.COLOR_GRAY2RGB) | ||
validData = True | ||
|
||
|
||
while (validData and lastIndex < len(data)): | ||
if (str(msg.header.stamp) == data[lastIndex][0]): | ||
if(data[lastIndex][1]!='-1' and data[lastIndex][2]!= '-1' and data[lastIndex][3]!='-1' and data[lastIndex][4]!='-1'): | ||
xmin = int(data[lastIndex][1]); ymin = int(data[lastIndex][2]); xmax = xmin+int(data[lastIndex][3]); ymax = ymin+int(data[lastIndex][4]); | ||
img = cv2.rectangle(np.array(img),(xmin,ymin),(xmax,ymax),(0,255,0),1) | ||
msgAnnoationArr.annotation_array.append(fillAnnotationMsg(1,xmin,ymin,xmax,ymax)) | ||
lastIndex += 1 | ||
else: | ||
validData = False; | ||
|
||
newMsg = bridge.cv2_to_imgmsg(img, encoding="rgb8") | ||
newMsg.header = msg.header | ||
newBag.write('/eyeBirdDataset/annotation/image_raw', newMsg, timestamp) | ||
|
||
msgAnnoationArr.header = msg.header | ||
newBag.write('/eyeBirdDataset/annotation/data', msgAnnoationArr, timestamp) | ||
|
||
bag.close() | ||
newBag.close() | ||
os.system('rosbag reindex ' + fileBagName + '_annotations.bag') | ||
os.system('rm ' + fileBagName + '_annotations.orig.bag') | ||
print(' File ' + fileBagName + '_annotations.bag saved\n') | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 3.0.2) | ||
project(eye_bird_dataset_msgs) | ||
|
||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
message_generation | ||
std_msgs | ||
) | ||
|
||
# search for all msg files | ||
FILE(GLOB messages_to_build RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/msg" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/msg/*.msg") | ||
|
||
# notify catkin to look at the previously found msg files | ||
add_message_files( | ||
FILES | ||
${messages_to_build} | ||
) | ||
|
||
## Generate added messages and services with any dependencies listed here | ||
generate_messages( | ||
DEPENDENCIES | ||
std_msgs | ||
) | ||
|
||
catkin_package( | ||
CATKIN_DEPENDS message_runtime std_msgs | ||
) | ||
|
||
include_directories( | ||
${catkin_INCLUDE_DIRS} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
bool detection | ||
int64 xmin | ||
int64 ymin | ||
int64 xmax | ||
int64 ymax | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Header header | ||
Annotation[] annotation_array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0"?> | ||
<package format="2"> | ||
<name>eye_bird_dataset_msgs</name> | ||
<version>0.0.0</version> | ||
<description>The eye_bird_dataset_msgs package</description> | ||
<maintainer email="[email protected]">Juan Pablo Rodriguez Gomez</maintainer> | ||
|
||
<license>MIT</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>message_generation</build_depend> | ||
<build_export_depend>message_generation</build_export_depend> | ||
<exec_depend>message_runtime</exec_depend> | ||
<build_depend>std_msgs</build_depend> | ||
<build_export_depend>std_msgs</build_export_depend> | ||
<exec_depend>std_msgs</exec_depend> | ||
|
||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python3 | ||
|
||
########################################################################### | ||
##### eye_bird_flip_images ##### | ||
##### Raul Tapia ##### | ||
##### GRVC Robotics Lab at University of Seville ##### | ||
########################################################################### | ||
|
||
# @file eye_bird_flip_images.py | ||
# @author Raul Tapia (raultapia _at_ us.es | github.com/raultapia) | ||
# @brief Flip raw images and events | ||
|
||
import os | ||
import rosbag | ||
import cv2 | ||
from cv_bridge import CvBridge | ||
|
||
filenameList = [ | ||
'Soccer_Base_1', | ||
'Soccer_Base_2', | ||
'Soccer_Base_3', | ||
'Soccer_ArUco_1', | ||
'Soccer_ArUco_2', | ||
'Soccer_People_1', | ||
'Soccer_People_2', | ||
'Soccer_Calibration', | ||
'Hills_Base_1', | ||
'Hills_Base_2', | ||
'Hills_Base_3', | ||
'Hills_ArUco_1', | ||
'Hills_ArUco_2', | ||
'Hills_Calibration', | ||
'Testbed_Base_1', | ||
'Testbed_Base_2', | ||
'Testbed_Base_3', | ||
'Testbed_ArUco_1', | ||
'Testbed_ArUco_2', | ||
'Testbed_ArUco_3', | ||
'Testbed_ArUco_4', | ||
'Testbed_ArUco_5', | ||
'Testbed_ArUco_6', | ||
'Testbed_Calibration' | ||
] | ||
|
||
for filename in filenameList: | ||
print(' Flipping ' + filename + '.bag ...') | ||
|
||
bag = rosbag.Bag(filename + '.bag') | ||
newBag = rosbag.Bag(filename + '_flipped.bag', 'w') | ||
bridge = CvBridge() | ||
|
||
for topic, msg, timestamp in bag.read_messages(): | ||
if topic == "/dvs/image_raw": | ||
img = bridge.imgmsg_to_cv2(msg, desired_encoding="passthrough") | ||
img = cv2.flip(img, -1) | ||
newMsg = bridge.cv2_to_imgmsg(img, encoding="mono8") | ||
newMsg.header = msg.header | ||
msg = newMsg | ||
|
||
if topic == "/dvs/events": | ||
for i in range(len(msg.events)): | ||
msg.events[i].x = msg.width - 1 - msg.events[i].x | ||
msg.events[i].y = msg.height - 1 - msg.events[i].y | ||
|
||
newBag.write(topic, msg, timestamp) | ||
|
||
bag.close() | ||
newBag.close() | ||
os.system('rosbag reindex ' + filename + '_flipped.bag') | ||
os.system('rm ' + filename + '_flipped.orig.bag') | ||
print(' File ' + filename + '_flipped.bag saved\n') |