6 from cv_bridge
import CvBridge
7 from jsk_recognition_msgs.msg
import VQATaskAction, VQATaskActionGoal
17 def request(self, questions_path, image_path, output_dir=None):
19 caption_goal = VQATaskActionGoal()
20 cv_image = cv2.imread(image_path)
21 image = self.
_bridge.cv2_to_imgmsg(cv_image,
"bgr8")
22 caption_goal.goal.image = image
23 with open(questions_path)
as f:
25 caption_goal.goal.questions.append(q)
30 for r
in caption_result.result.result:
31 result[r.question] = r.answer
32 image_name = os.path.splitext(os.path.basename(image_path))[0]
33 json_name = image_name +
".json"
35 save_path = os.path.join(output_dir, json_name)
37 save_path = os.path.join(os.path.dirname(image_path), json_name)
38 with open(save_path,
"w")
as f:
39 json.dump(result, f, indent=4, separators=(
',',
': '))
41 parser = argparse.ArgumentParser(description=
"CLI interface for VQA action client")
42 parser.add_argument(
"questions_path", help=
"Question text file path of VQA input", type=str)
43 parser.add_argument(
"image_path", help=
"Image file path of VQA input", type=str)
44 parser.add_argument(
"-o",
"--output", default=
None)
46 args = parser.parse_args()
48 if __name__ ==
"__main__":
49 rospy.init_node(
"vqa_request_client", anonymous=
True)
51 questions_path = args.questions_path
52 image_path = args.image_path
54 client.request(questions_path, image_path, output)