Skip to content

Commit

Permalink
[jsk_tools/camera_check.py] Add is_image_valid function to check came…
Browse files Browse the repository at this point in the history
…ra is valid
  • Loading branch information
iory committed Nov 3, 2018
1 parent 26c454d commit f143ef6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion jsk_tools/src/camera_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
import diagnostic_updater
import diagnostic_msgs
from sensor_msgs.msg import Image
import cv2
from cv_bridge import CvBridge
from cv_bridge import CvBridgeError

from jsk_tools.sanity_lib import checkUSBExist


class CameraCheck(object):

def __init__(self):
def __init__(self, device_path=None):
self.bridge = CvBridge()
self.topic_names = rospy.get_param('~topic_names', [])
self.device_type = rospy.get_param("~device_type", 'usb')
self.device_path = rospy.get_param('~device_path', None)
Expand Down Expand Up @@ -97,6 +101,23 @@ def check_topic(self, stat):
stat.add('topic {} {} Hz'.format(topic_name, topic_hz))
return stat

def is_image_valid(self, msg):
try:
cv_image = self.bridge.imgmsg_to_cv2(msg, "bgr8")
sum_of_pixels = max(cv2.sumElems(cv_image))
except CvBridgeError as e:
rospy.logerr(
"[%s] failed to convert image to cv",
self.__class__.__name__)
return False
rospy.loginfo(
"[%s] sum of pixels is %d at %s",
self.__class__.__name__,
sum_of_pixels, msg.header.stamp.secs)
if sum_of_pixels == 0:
return False
return True

def run(self):
while not rospy.is_shutdown():
self.subscribe()
Expand Down

0 comments on commit f143ef6

Please sign in to comment.