fri i
play

FRI I ROS & OpenCV Instructor: Justin Hart - PowerPoint PPT Presentation

CS 309: Autonomous Robots FRI I ROS & OpenCV Instructor: Justin Hart http://justinhart.net/teaching/2020_spring_cs309/ OpenCV Open Computer Vision System Officially launched in 1999 at Intel Research Original purpose


  1. CS 309: Autonomous Robots FRI I ROS & OpenCV Instructor: Justin Hart http://justinhart.net/teaching/2020_spring_cs309/

  2. OpenCV • Open Computer Vision System • Officially launched in 1999 at Intel Research • Original purpose – Studying CPU-intensive applications • Willow Garage (kicked off in 2006) • Hosted • OpenCV • Point Cloud Library • OpenCV is Open Source! • BSD license • Now run by OpenCV.org

  3. OpenCV • Includes a wealth of low-level vision processing • In this class, we will do a few basics • Color channel filtering • Blob detection • Supports 2D and 3D vision • Has many features • Stereo vision • Structure from motion • Face recognition • Motion tracking • And tries to stay on top of incorporating tools that are of general broad interest and use

  4. The Very Basics • We learn an introductory technique called “Color Segmentation” or “Color Blob Detection” • Color channels • Color channel subtraction • Thresholding • Contour Detection • Masking

  5. OpenCV and ROS • OpenCV and ROS use different formats • cv_bridge helps solve this

  6. Color Channels • Colors are represented using different systems • BGR → Blue, Green, Red • Also RGB, RGBA, BGRA Alpha → Transparency • • HSV → Hue, Saturation, Value • Others get more complex • HSL → Hue, Saturation, Luma How brightly lit something • appears

  7. BGR • Each pixel gets a color intensity for each channel • This is how bright that channel is • The blend of blue, green, and red becomes the final color

  8. cv::Mat • OpenCV stores images in its matrix type • cv::mat • A matrix has rows and columns of numbers • For an image, this is how tall and wide the image is • In OpenCV each matrix cell (number) can have more than one channel • The matrices have types which dictate this representation • CV_8UC3 - CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4 • CV_8SC1 • CV_64F • BGR images are stored in CV_8UC3 • OpenCV, 8 bits per channel, unsigned characters, 3 channels

  9. Color Values • Unsigned character → 8 bits long • 0..255 • Highest intensity 255 • Lowest intensity 0 • As the intensity goes higher, the color in that channel becomes brighter

  10. cv::split() Break an image with several channels into several 1 channel images std::vector<cv::Mat> chans; cv::split(image, chans);

  11. Input Image and Three Channels

  12. Color Channel Images • Notice that as the intensity of a channel goes up, the greyscale pixels become brighter. • Look back at the image in the previous slide, each cup becomes brightest in one particular image.

  13. Example, finding the blue cup • Let’s find the blue cup

  14. Color Channel Subtraction • cv::subtract() • Subtract one cv::Mat from another • cv::Mat bMinusG • cv::subtract(chans[0], chans[1], bMinusG) Blue channel minus red channel Blue channel minus green channel

  15. Picking out the blue pixels Blue minus red is really bright! We can just pick the pixels that are bright enough! Blue channel minus red channel Blue channel minus green channel

  16. Image Thresholding • There are pixels illuminated that are not the cup • But the brightest ones belong to the cup • Pick the pixels only as bright as some value • Image thresholding • Specify a minimum and maximum value cv::threshold(input_image, output_image, threshold_value, value_when_above_threshold, threshold_type) We will use only cv::THRESH_BINARY cv::Mat bThresh; cv::threshold(bMinusR, bThresh, 50, 255, cv::THRESH_BINARY);

  17. Contour Detection • Detects closed image contours • “Blobs” in the image – connected areas of illuminated pixels

  18. Find the area of each contour cv::contourArea(contours[i]) • Computes the area of the contour • In your program, find the biggest contour and track it • This gets rid of the small, noisy stuff

  19. Image Masking • Selecting only certain pixels • Uses a “mask” • A 1- channel image where the pixels to be included are turned “on” (usually 255) cv::Mat mask = cv::Mat::zeros(image.rows, image.cols, CV_8UC1); cv::drawContours(mask, contours, maxSizeContour, cv::Scalar(255), cv::LineTypes::FILLED, 8, hierarchy); • copyTo can be used with a mask image.copyTo(blueCupImg, mask);

  20. For Homework 3 • Create a ROS package which puts the blue, green, and red cups together. • Must build under catkin build with g++ – The three separate cups get published on ROS topics /color_filter/blue_cup /color_filter/green_cup /color_filter/red_cup • The three cups together get published on a ROS topic in a composite image /color_filter/cups

  21. rviz – The ROS Visualizer ● rosrun rviz rviz ● What you get should look something like this.

  22. ● Clicking the add button will allow you to add things to visualize.

  23. ● “By topic” will list the available topics.

  24. ● Expand until you see what you are interested in.

  25. ● Clicking “Okay” should add it to the interface.

  26. ● You can rearrange and resize windows as appropriate.

  27. ● Use rviz to help develop and debug your homework.

  28. What should my program do? ● You should write 1 (and only 1) ROS node ● It should publish 4 topics – /color_filter/blue_cup – /color_filter/green_cup – /color_filter/red_cup – /color_filter/cups ● The first three should show only the blue, green, and red cup, respectively. ● The third should show all three together.

  29. How should my program do this? ● Finding the BLUE cup is demonstrated in the example on justinhart.net – You may need to modify your package.xml and CMakelists.txt as per the Piazza discussion ● Finding the RED and GREEN cups is a variation on this

  30. How should my program do this? ● /color_filter/cups contains all three, though! ● RIGHT! I’m not going to tell you exactly how to do this, because it would make the homework too easy for you to learn anything. ● But you will use cv::bitwise_or to do it – And if you Google cv::bitwise_or, and understand how you found the blue,green, and red cups; the example for bitwise_or is almost exact directions on how this works.

  31. So.. display the cups, right? ● NO!! – Publish a ROS TOPIC for each of the the blue, green, and red cups, respectively, and one containing all three. – You should be able to see this topic using rviz – In fact, turn off the cv::imshows in your c++ code before you submit (unless you’ve already submitted).

  32. How do I publish the ROS topic? ● cv_bridge – http://wiki.ros.org/cv_bridge/Tutorials/Usin gCvBridgeToConvertBetweenROSImages AndOpenCVImages – Then publish the topic as in our previous lectures. – See also: https://stackoverflow.com/questions/27080 085/how-to-convert-a-cvmat-into-a-sensor- msgs-in-ros

  33. My ROS topic complains that I’ve advertised more than once ● Call advertise() in your main, and publish() in your callback. – publish() sends the image – advertise() says that you will publish on a topic

  34. My ROS topic complains that I’ve advertised more than once ● Call advertise() in your main, and publish() in your callback. – publish() sends the image – advertise() says that you will publish on a topic ● And you can’t advertise the same topic more than once per node.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend