{"action":"created","comment":{"url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/comments/29914566","id":29914566,"diff_hunk":"@@ -0,0 +1,77 @@\n+#!/usr/bin/env python\n+# -*- coding: utf-8 -*-\n+#\n+import cv2\n+\n+import rospy\n+import cv_bridge\n+from sensor_msgs.msg import Image\n+from std_msgs.msg import String\n+\n+\n+class ImageTimeDiff(object):\n+    \"\"\"Publish difference between stored image and current input one\n+\n+    Publications:\n+        * ~output/{namespace}: diff between stored image and current input\n+\n+    Subscriptions:\n+        * ~input: input raw image\n+        * ~start_comparing: msg to store image and start comparing\n+        * ~stop_comparing: msg to relase image and stop comparing\n+\n+    \"\"\"\n+    def __init__(self):\n+        rospy.Subscriber('~input', Image, self._cb_image)\n+        rospy.Subscriber('~start_comparing', String, self._cb_start)\n+        rospy.Subscriber('~stop_comparing', String, self._cb_stop)\n+        self.pub_stored = {}\n+        self.imgmsg = None\n+\n+    def _cb_image(self, msg):\n+        self.imgmsg = msg\n+\n+    def _cb_start(self, msg):\n+        stamp = rospy.Time.now()\n+        namespace = msg.data\n+        pub = rospy.Publisher('~output/{0}'.format(namespace),\n+                              Image,\n+                              queue_size=1)\n+        pub_debug = rospy.Publisher('~debug/{0}'.format(namespace),\n+                                    Image, queue_size=1)\n+        while self.imgmsg is None or self.imgmsg.header.stamp < stamp:\n+            # wait for image at the same time\n+            rospy.sleep(0.1)\n+        imgmsg = self.imgmsg\n+        bridge = cv_bridge.CvBridge()\n+        img = bridge.imgmsg_to_cv2(imgmsg, desired_encoding='mono8')\n+        self.pub_stored[namespace] = pub, img, pub_debug\n+\n+    def _cb_stop(self, msg):\n+        namespace = msg.data\n+        del self.pub_stored[namespace]\n+\n+    def spin_once(self):\n+        if self.imgmsg is None:\n+            return\n+        imgmsg = self.imgmsg\n+        bridge = cv_bridge.CvBridge()\n+        img = bridge.imgmsg_to_cv2(imgmsg, desired_encoding='mono8')\n+        pub_stored = self.pub_stored\n+        for ns, (pub_diff, img_stored, pub_debug) in pub_stored.items():\n+            # compute diff for all publications\n+            diff = cv2.absdiff(img, img_stored)\n+            pub_diff.publish(bridge.cv2_to_imgmsg(diff))\n+            pub_debug.publish(bridge.cv2_to_imgmsg(img_stored))\n+\n+    def spin(self):\n+        rate = rospy.Rate(rospy.get_param('rate', 10))\n+        while not rospy.is_shutdown():\n+            self.spin_once()","path":"jsk_perception/scripts/image_time_diff.py","position":70,"original_position":70,"commit_id":"c337095c8284f5c8c1c70e6a799b5f2da70a7997","original_commit_id":"c337095c8284f5c8c1c70e6a799b5f2da70a7997","user":{"login":"wkentaro","id":4310419,"avatar_url":"https://avatars.githubusercontent.com/u/4310419?v=3","gravatar_id":"","url":"https://api.github.com/users/wkentaro","html_url":"https://github.com/wkentaro","followers_url":"https://api.github.com/users/wkentaro/followers","following_url":"https://api.github.com/users/wkentaro/following{/other_user}","gists_url":"https://api.github.com/users/wkentaro/gists{/gist_id}","starred_url":"https://api.github.com/users/wkentaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wkentaro/subscriptions","organizations_url":"https://api.github.com/users/wkentaro/orgs","repos_url":"https://api.github.com/users/wkentaro/repos","events_url":"https://api.github.com/users/wkentaro/events{/privacy}","received_events_url":"https://api.github.com/users/wkentaro/received_events","type":"User","site_admin":false},"body":"But I need to process image files here.\r\nHow can I use rospy.spin() when I need process something?","created_at":"2015-05-08T03:12:55Z","updated_at":"2015-05-08T03:12:55Z","html_url":"https://github.com/jsk-ros-pkg/jsk_recognition/pull/913#discussion_r29914566","pull_request_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/913","_links":{"self":{"href":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/comments/29914566"},"html":{"href":"https://github.com/jsk-ros-pkg/jsk_recognition/pull/913#discussion_r29914566"},"pull_request":{"href":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/913"}}},"pull_request":{"url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/913","id":34941074,"html_url":"https://github.com/jsk-ros-pkg/jsk_recognition/pull/913","diff_url":"https://github.com/jsk-ros-pkg/jsk_recognition/pull/913.diff","patch_url":"https://github.com/jsk-ros-pkg/jsk_recognition/pull/913.patch","issue_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/issues/913","number":913,"state":"open","locked":false,"title":"[jsk_perception] Publish the difference between start and current image","user":{"login":"wkentaro","id":4310419,"avatar_url":"https://avatars.githubusercontent.com/u/4310419?v=3","gravatar_id":"","url":"https://api.github.com/users/wkentaro","html_url":"https://github.com/wkentaro","followers_url":"https://api.github.com/users/wkentaro/followers","following_url":"https://api.github.com/users/wkentaro/following{/other_user}","gists_url":"https://api.github.com/users/wkentaro/gists{/gist_id}","starred_url":"https://api.github.com/users/wkentaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wkentaro/subscriptions","organizations_url":"https://api.github.com/users/wkentaro/orgs","repos_url":"https://api.github.com/users/wkentaro/repos","events_url":"https://api.github.com/users/wkentaro/events{/privacy}","received_events_url":"https://api.github.com/users/wkentaro/received_events","type":"User","site_admin":false},"body":"upper_left: raw_image\r\nupper_center: mask_image\r\nupper_right: mask_applied_image\r\nlower_right: hue of mask_applied_image\r\nlower_center: stored_image\r\nlower_left: diff of stored_image","created_at":"2015-05-07T17:56:34Z","updated_at":"2015-05-08T03:12:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0bc4ec3f478d2a52d2fef300169b8fd28a0eac78","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/913/commits","review_comments_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/913/comments","review_comment_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/issues/913/comments","statuses_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/statuses/c337095c8284f5c8c1c70e6a799b5f2da70a7997","head":{"label":"wkentaro:image-time-diff","ref":"image-time-diff","sha":"c337095c8284f5c8c1c70e6a799b5f2da70a7997","user":{"login":"wkentaro","id":4310419,"avatar_url":"https://avatars.githubusercontent.com/u/4310419?v=3","gravatar_id":"","url":"https://api.github.com/users/wkentaro","html_url":"https://github.com/wkentaro","followers_url":"https://api.github.com/users/wkentaro/followers","following_url":"https://api.github.com/users/wkentaro/following{/other_user}","gists_url":"https://api.github.com/users/wkentaro/gists{/gist_id}","starred_url":"https://api.github.com/users/wkentaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wkentaro/subscriptions","organizations_url":"https://api.github.com/users/wkentaro/orgs","repos_url":"https://api.github.com/users/wkentaro/repos","events_url":"https://api.github.com/users/wkentaro/events{/privacy}","received_events_url":"https://api.github.com/users/wkentaro/received_events","type":"User","site_admin":false},"repo":{"id":31913659,"name":"jsk_recognition","full_name":"wkentaro/jsk_recognition","owner":{"login":"wkentaro","id":4310419,"avatar_url":"https://avatars.githubusercontent.com/u/4310419?v=3","gravatar_id":"","url":"https://api.github.com/users/wkentaro","html_url":"https://github.com/wkentaro","followers_url":"https://api.github.com/users/wkentaro/followers","following_url":"https://api.github.com/users/wkentaro/following{/other_user}","gists_url":"https://api.github.com/users/wkentaro/gists{/gist_id}","starred_url":"https://api.github.com/users/wkentaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wkentaro/subscriptions","organizations_url":"https://api.github.com/users/wkentaro/orgs","repos_url":"https://api.github.com/users/wkentaro/repos","events_url":"https://api.github.com/users/wkentaro/events{/privacy}","received_events_url":"https://api.github.com/users/wkentaro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wkentaro/jsk_recognition","description":"JSK perception ROS packages","fork":true,"url":"https://api.github.com/repos/wkentaro/jsk_recognition","forks_url":"https://api.github.com/repos/wkentaro/jsk_recognition/forks","keys_url":"https://api.github.com/repos/wkentaro/jsk_recognition/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wkentaro/jsk_recognition/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wkentaro/jsk_recognition/teams","hooks_url":"https://api.github.com/repos/wkentaro/jsk_recognition/hooks","issue_events_url":"https://api.github.com/repos/wkentaro/jsk_recognition/issues/events{/number}","events_url":"https://api.github.com/repos/wkentaro/jsk_recognition/events","assignees_url":"https://api.github.com/repos/wkentaro/jsk_recognition/assignees{/user}","branches_url":"https://api.github.com/repos/wkentaro/jsk_recognition/branches{/branch}","tags_url":"https://api.github.com/repos/wkentaro/jsk_recognition/tags","blobs_url":"https://api.github.com/repos/wkentaro/jsk_recognition/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wkentaro/jsk_recognition/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wkentaro/jsk_recognition/git/refs{/sha}","trees_url":"https://api.github.com/repos/wkentaro/jsk_recognition/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wkentaro/jsk_recognition/statuses/{sha}","languages_url":"https://api.github.com/repos/wkentaro/jsk_recognition/languages","stargazers_url":"https://api.github.com/repos/wkentaro/jsk_recognition/stargazers","contributors_url":"https://api.github.com/repos/wkentaro/jsk_recognition/contributors","subscribers_url":"https://api.github.com/repos/wkentaro/jsk_recognition/subscribers","subscription_url":"https://api.github.com/repos/wkentaro/jsk_recognition/subscription","commits_url":"https://api.github.com/repos/wkentaro/jsk_recognition/commits{/sha}","git_commits_url":"https://api.github.com/repos/wkentaro/jsk_recognition/git/commits{/sha}","comments_url":"https://api.github.com/repos/wkentaro/jsk_recognition/comments{/number}","issue_comment_url":"https://api.github.com/repos/wkentaro/jsk_recognition/issues/comments{/number}","contents_url":"https://api.github.com/repos/wkentaro/jsk_recognition/contents/{+path}","compare_url":"https://api.github.com/repos/wkentaro/jsk_recognition/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wkentaro/jsk_recognition/merges","archive_url":"https://api.github.com/repos/wkentaro/jsk_recognition/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wkentaro/jsk_recognition/downloads","issues_url":"https://api.github.com/repos/wkentaro/jsk_recognition/issues{/number}","pulls_url":"https://api.github.com/repos/wkentaro/jsk_recognition/pulls{/number}","milestones_url":"https://api.github.com/repos/wkentaro/jsk_recognition/milestones{/number}","notifications_url":"https://api.github.com/repos/wkentaro/jsk_recognition/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wkentaro/jsk_recognition/labels{/name}","releases_url":"https://api.github.com/repos/wkentaro/jsk_recognition/releases{/id}","created_at":"2015-03-09T17:51:36Z","updated_at":"2015-03-10T13:03:49Z","pushed_at":"2015-05-08T03:07:56Z","git_url":"git://github.com/wkentaro/jsk_recognition.git","ssh_url":"git@github.com:wkentaro/jsk_recognition.git","clone_url":"https://github.com/wkentaro/jsk_recognition.git","svn_url":"https://github.com/wkentaro/jsk_recognition","homepage":"https://github.com/jsk-ros-pkg/jsk_recognition","size":36046,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jsk-ros-pkg:master","ref":"master","sha":"cf3fb25bc02ba4f464e6318cfc07533a0bcb281c","user":{"login":"jsk-ros-pkg","id":6836654,"avatar_url":"https://avatars.githubusercontent.com/u/6836654?v=3","gravatar_id":"","url":"https://api.github.com/users/jsk-ros-pkg","html_url":"https://github.com/jsk-ros-pkg","followers_url":"https://api.github.com/users/jsk-ros-pkg/followers","following_url":"https://api.github.com/users/jsk-ros-pkg/following{/other_user}","gists_url":"https://api.github.com/users/jsk-ros-pkg/gists{/gist_id}","starred_url":"https://api.github.com/users/jsk-ros-pkg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsk-ros-pkg/subscriptions","organizations_url":"https://api.github.com/users/jsk-ros-pkg/orgs","repos_url":"https://api.github.com/users/jsk-ros-pkg/repos","events_url":"https://api.github.com/users/jsk-ros-pkg/events{/privacy}","received_events_url":"https://api.github.com/users/jsk-ros-pkg/received_events","type":"Organization","site_admin":false},"repo":{"id":17374628,"name":"jsk_recognition","full_name":"jsk-ros-pkg/jsk_recognition","owner":{"login":"jsk-ros-pkg","id":6836654,"avatar_url":"https://avatars.githubusercontent.com/u/6836654?v=3","gravatar_id":"","url":"https://api.github.com/users/jsk-ros-pkg","html_url":"https://github.com/jsk-ros-pkg","followers_url":"https://api.github.com/users/jsk-ros-pkg/followers","following_url":"https://api.github.com/users/jsk-ros-pkg/following{/other_user}","gists_url":"https://api.github.com/users/jsk-ros-pkg/gists{/gist_id}","starred_url":"https://api.github.com/users/jsk-ros-pkg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsk-ros-pkg/subscriptions","organizations_url":"https://api.github.com/users/jsk-ros-pkg/orgs","repos_url":"https://api.github.com/users/jsk-ros-pkg/repos","events_url":"https://api.github.com/users/jsk-ros-pkg/events{/privacy}","received_events_url":"https://api.github.com/users/jsk-ros-pkg/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jsk-ros-pkg/jsk_recognition","description":"JSK perception ROS packages","fork":false,"url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition","forks_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/forks","keys_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/teams","hooks_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/hooks","issue_events_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/issues/events{/number}","events_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/events","assignees_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/assignees{/user}","branches_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/branches{/branch}","tags_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/tags","blobs_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/git/refs{/sha}","trees_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/statuses/{sha}","languages_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/languages","stargazers_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/stargazers","contributors_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/contributors","subscribers_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/subscribers","subscription_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/subscription","commits_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/commits{/sha}","git_commits_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/git/commits{/sha}","comments_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/comments{/number}","issue_comment_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/issues/comments{/number}","contents_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/contents/{+path}","compare_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/merges","archive_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/downloads","issues_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/issues{/number}","pulls_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls{/number}","milestones_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/milestones{/number}","notifications_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/labels{/name}","releases_url":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/releases{/id}","created_at":"2014-03-03T17:59:44Z","updated_at":"2015-05-07T23:49:37Z","pushed_at":"2015-05-08T03:07:56Z","git_url":"git://github.com/jsk-ros-pkg/jsk_recognition.git","ssh_url":"git@github.com:jsk-ros-pkg/jsk_recognition.git","clone_url":"https://github.com/jsk-ros-pkg/jsk_recognition.git","svn_url":"https://github.com/jsk-ros-pkg/jsk_recognition","homepage":"https://github.com/jsk-ros-pkg/jsk_recognition","size":49054,"stargazers_count":13,"watchers_count":13,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":6,"forks":27,"open_issues":6,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/913"},"html":{"href":"https://github.com/jsk-ros-pkg/jsk_recognition/pull/913"},"issue":{"href":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/issues/913"},"comments":{"href":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/issues/913/comments"},"review_comments":{"href":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/913/comments"},"review_comment":{"href":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/pulls/913/commits"},"statuses":{"href":"https://api.github.com/repos/jsk-ros-pkg/jsk_recognition/statuses/c337095c8284f5c8c1c70e6a799b5f2da70a7997"}}}}