Repository navigation
Intra-process image pipeline example - #12
Conversation
|
I found this bug in OpenCV on Windows (see #13): replacing |
There was a problem hiding this comment.
k. I'll keep OpenCV in its own category instead of sorting it into alphabetical order, since it's not a ROS package (I assume that's our convention based on https://github.com/ros2/demos/blob/master/image_tools/CMakeLists.txt).
There was a problem hiding this comment.
Sounds good. With same below I referred to line 33.
8e4a55d to
2bc569f
Compare
There was a problem hiding this comment.
Why would the next node in the pipeline subscribe to this relayed topic rather then the original once?
There was a problem hiding this comment.
@wjwwood suggested that the read-only node republishes the message when we discussed the design of this demo on Monday, though looking at the code now I'm not sure why this is better.
There was a problem hiding this comment.
It prevents copying of the message since there are never more than one subscription for each publisher.
|
Ok I updated this pr with a new example: https://github.com/ros2/demos/pull/12/files#diff-9c1f8132951cbb58bc4bbd4f97b870a6 Required changes in |
|
This is an example of the output from the above linked new example: |
|
Ok, so I've got a pretty nice demo going now. See the files in: This is just a refactoring/reorganization of what @jacquelinekay did (Thanks for that btw, gave me a huge head start on the CV stuff). So, now if you run The demo is made up of three nodes at the moment: I managed to find a way to create a cv::Mat and operate on it without copying the data out of the message. So the only copying is when I copy the data from the captured image into the original ros message. I've also added two other toy problems. I still have to write some of the tutorial, but I'll hopefully be able to knock that out quick now that I've got some of the demo done. |
There was a problem hiding this comment.
Pass the input strings as const references.
There was a problem hiding this comment.
Can you give some justification for using std::thread instead of create_wall_timer for publishing this message? My guess is that you don't want the image capture to run in the same thread as the executor, but you also don't want to use a MultiThreadedExecutor because we haven't vetted the intra-process stuff for thread safety yet.
Also, I noticed you don't sleep in the loop function. Does OpenCV block when we get a new frame? Or is this a busy while loop?
There was a problem hiding this comment.
I used a thread because I want the loop to run continuously (without a sleep), so the timer isn't well suited for that. OpenCV will block when you call frame_ << cap_;.
There was a problem hiding this comment.
Also, I added some thread safety protection on the publishing side:
There was a problem hiding this comment.
The other idea I had was to add an "on_idle" callback list for the executor, which is similar to other event loop systems:
- WxWidgets has an idle event which you can handle and do extra work in: http://www.wxpython.org/docs/api/wx.IdleEvent-class.html
- In Qt you can use a Timer with timeout 0 (might work for us too) or processEvent.
As a special case, a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed. This can be used to do heavy work while providing a snappy user interface:
- libuv also has idle processing: https://nikhilm.github.io/uvbook/basics.html#idling
There was a problem hiding this comment.
Yeah, the mechanism for prioritizing queued work in the Executor is a bit inflexible right now, or should I say non-existent. (related: ros2/rclcpp/issues/76) Another feature to push on after the release...
|
With regards to avoiding the bug Esteve found on Windows, I think you can convert to a CvMat without incurring copy using this constructor (it just assigns a data pointer without allocating new memory): you can do this just before calling |
|
@jacquelinekay yeah, that's what I did: |
a0bfd52 to
b70baf3
Compare
|
You guys are killing me... rebased again. |
|
None of the classes is in a proper namespace following the package name. |
There was a problem hiding this comment.
Two nodes should not have the same name.
There was a problem hiding this comment.
That's not the node name, and so they have different names.
I reverted the change in 58f7339.
There was a problem hiding this comment.
Oh, it is actually the topic name. That is unexpected to change the constructor argument semantic in a subclass. Good that you catched it.
There was a problem hiding this comment.
Yeah, It's not very nice, but at the time I thought it was unnecessary to additionally pass the node name.
b70baf3 to
f38c978
Compare
|
I just rebased this and updated with feedback from @dirk-thomas. The non-rebased version of the branch can be found at https://github.com/ros2/demos/tree/intra_process_img-prerebase if you need it @wjwwood |
58f7339 to
983c98d
Compare
|
Ok, other than the flaky tests and a few compiler warnings on Windows (which I fixed and tested manually) this looks good to go. |
Intra-process image pipeline example
|
Fixing windows warnings in #20 |

This is a first pass at an example that exercises intra-process communication for an image processing pipeline.
Adds:
Todo:
convert_message_to_frameperforms a zero-copy conversion from ROS message to OpenCV Mat "frame" by assigning to Mat data pointer to the start of the ROS Image data vector. However,convert_frame_to_messagecopies the Mat data into the ROS Image data vector, because I couldn't figure out how to directly assign the pointer to the underlying data of a vector (and I don't think this is possible).