Skip to content

Commit

Permalink
do not error
Browse files Browse the repository at this point in the history
```
    if (len(img.shape) == 2 and
AttributeError: 'NoneType' object has no attribute 'shape'
```
when file is not found
  • Loading branch information
k-okada committed Oct 17, 2021
1 parent 15d5681 commit 6e8f2a8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions jsk_perception/node_scripts/image_publisher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import os, sys
from threading import Lock

import cv2
Expand Down Expand Up @@ -43,18 +43,18 @@ def _cb_dyn_reconfig(self, config, level):
file_name = config['file_name']
config['file_name'] = os.path.abspath(file_name)
img = cv2.imread(file_name, cv2.IMREAD_UNCHANGED)
# when file is gray scale but encoding is not grayscale,
# load the image again in color
if (len(img.shape) == 2 and
getCvType(self.encoding) not in [
cv2.CV_8UC1, cv2.CV_16UC1, cv2.CV_32FC1]):
img = cv2.imread(file_name, cv2.IMREAD_COLOR)
if img is None:
rospy.logwarn('Could not read image file: {}'.format(file_name))
with self.lock:
self.imgmsg = None
else:
rospy.loginfo('Read the image file: {}'.format(file_name))
# when file is gray scale but encoding is not grayscale,
# load the image again in color
if (len(img.shape) == 2 and
getCvType(self.encoding) not in [
cv2.CV_8UC1, cv2.CV_16UC1, cv2.CV_32FC1]):
img = cv2.imread(file_name, cv2.IMREAD_COLOR)
with self.lock:
self.imgmsg = self.cv2_to_imgmsg(img, self.encoding)
return config
Expand Down

0 comments on commit 6e8f2a8

Please sign in to comment.