[ERROR] bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object>> ; RuntimeError: dictionary changed size during iteration
I am working on camera calibration ros node. When there is a good sample the node takes the good sample into cache. At that time I am writing images of that frame into my local system and trying to compare if images written at that moment are similar to images being subscribed during the node initialization of the camera_calibrator script file. For that I have written a message filter, i.e. register callback function.
msub = message_filters.Subscriber('image', sensor_msgs.msg.Image)
sub1 = message_filters.Subscriber('/webcam', sensor_msgs.msg.Image)
self.ts = message_filters.ApproximateTimeSynchronizer([msub,sub1], 10,0.1,allow_headerless=True)
Later somewhere inside my code I call:
self.ts.registerCallback(image_callback,(cnt))
def image_callback(msg1, msg2, cnt):
print("Received an image!")
try:
# Convert your ROS Image message to OpenCV2
cv2_img2 = bridge.imgmsg_to_cv2(msg2, "bgr8")
cv2_img1 = bridge.imgmsg_to_cv2(msg1, "bgr8")
except CvBridgeError as e:
print(e)
else:
# Save your OpenCV2 image as a jpeg
cv2.imwrite('/home/test_' + str(cnt)+ '.png', cv2_img2)
cv2.imwrite('/home/ori_time_' + str(cnt)+ '.png', cv2_img1)
It does write images but I get following error after few images are wrtiiten:
[ERROR] [1663774344.611751]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7f47e6ba6190>>
Traceback (most recent call last):
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/opt/ros/noetic/lib/python3/dist-packages/message_filters/__init__.py", line 76, in callback
self.signalMessage(msg)
File "/opt/ros/noetic/lib/python3/dist-packages/message_filters/__init__.py", line 58, in signalMessage
cb(*(msg + args))
File "/opt/ros/noetic/lib/python3/dist-packages/message_filters/__init__.py", line 330, in add
self.signalMessage(*msgs)
File "/opt/ros/noetic/lib/python3/dist-packages/message_filters/__init__.py", line 57, in signalMessage
for (cb, args) in self.callbacks.values():
RuntimeError: dictionary changed size during iteration
I am unsure why I am getting this. I also tried
self.ts = message_filters.TimeSynchronizer([msub,sub1], 1)
It didn't work. Anyone knows why I am getting runtime error? How to solve this?
I am publishing these images from webcam continuously.
cnt
to make itself.ts.registerCallback(image_callback)
anddef image_callback(msg1, msg2)
. Setcnt = msg1.header.stamp
inside the callback./home/test_
and/home/ori_time_
.