CADC Ground Investigation Visual Solution
We want to apply computer vision to the plane to fullfill ground investigation task automatically.
The input image looks like this:
And we hope the output prediction to be 56.
(requirment.txt will be added afterwards)
Basic OpenCV methods is required.
Recommended learning site:
Source code
in detect.py
, there are two large function
1 | def detect_target(image): |
detect_target
receive image data(three channels, BGR), detect the colored targets and returns the index of them.
index:
rect
, indicating the information of the minimum bounding rectangleNote: What is Box2D type rect
?
index | description |
---|---|
rect[0] | the location of the box’s center (x,y) |
rect[1][0] | width of the box(the length of the side which will be first reached by the horizontal line when rotating counter-clockwise) |
rect[1][1] | height |
rect[2] | rotation angle |
First we need to convert the color layout from BGR to HSV, which is easier to judge color.
1 | image_hsv=cv2.cvtColor(image_cut,cv2.COLOR_BGR2HSV) |
Then define a mask that filter the color(hue) range from 160-179 or 0-10 (red),
1 | red1=np.array([0,100,100]) |
And apply the mask to the picture
1 | after_mask=cv2.add(image_cut, np.zeros(np.shape(image_cut), dtype=np.uint8), mask=mask) |
Turn the after mask image into binary image and adapt close and open processing to fill holes and cancel noise.
1 | kernel=np.ones([3,3],np.uint8) |
Then, find the contours of the processed image.
For each contour, adapt filters such as area, the ratio of the height and width of bounding rectangle.
If these restrictions are fullfilled, append the index of bounding rectangle and min area rectangle to two lists respectively, and return the lists.
1 | contours, hier=cv2.findContours(Open,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) |
Study note for ROS subscriber.
How to realize a subscriber
Also we put this node into function package learning_topic
Create velocity_publisher.cpp
file in learning_topic/src
:
1 |
|
Note
Steps same as publisher
Add two lines to learning\_topic/CMakeLists.txt
(in build part):
1 | add_executable(velocity_publisher src/pose_subscriber.cpp) |
1 | $ cd ~/ROS_study/catkin_ws |
The output of pose_subscriber:
1 | ... |
Study note for ROS publisher.
Take turtlesim as the example.
We write a program acting like a publisher and sending controlling messages.
1 | $ cd catkin_ws/src |
can see:
1 | $ ls |
How to realize a publisher?
create velocity_publisher.cpp
file in learning_topic/src
1 |
|
What is queue length?
Steps:
Add two lines to learning\_topic/CMakeLists.txt
(in build part):
1 | add_executable(velocity_publisher src/velocity_publisher.cpp) |
1 | $ cd ~/ROS_study/catkin_ws |
Then, you can see turtle:
And outputs:
1 | ... |
Studying note for regular expression
Regular expression describes a pattern of matching string
Can be used to detect/replace/take out specific substring
symbol | description | example |
---|---|---|
^ | match the beginning of he line | |
[ABC] | match all char in […] | [aeiou]: google runoob taobao |
[^ABC] | match all except those in […] | |
[A-Z] | describe an interval | [a-z] matchs all lower case char |
(…) | set groups | |
\1…\n | match the same elements as nth group | |
{n} | the front element repeats n times | |
{n,} | the front element repeats at least n times | |
{n,m} | the front element repeats at least n and at most m times | |
. | match any char except (\n,\r), same with [^\n\r] | |
\s\S | match all, \s:match all space char, \S:match all non space char, ‘return’ not included | |
\w | match letter,number,underline, equal to [A-Za-z0-9 ] | |
\cx | match the control char indicated by x(A-Z/a-z) | \cM: Control-M or return char |
\f | match a page change char | |
\n\r | match a return symbol | |
\t | match a tab | |
\v | match a vertical tab | |
$ | match the end of the string, to match $ itself, use $ | |
* | match the front subexpression multiple or zero times, use \* to match * | |
+ | match the front subexpression multiple or one times, use \+ | |
. | match any single char except \n | |
[ | mark the beginning of a []expression | |
? | match the front subexpression one or zero times, or indicate a non-greedy qualifier | |
| | logic or |
In cpp, we use std::regex
to express regular expression, supporting ECMAScripts as default.
Use regex_match()
to match xml (or html) format:
1 | std::regex reg("<.*>.*</.*>"); |
Use std::regex_search
.
As long as there exists targets in the string, it will return.
1 | std::regex reg("<(.*)>(.*)</(\\1)>"); |
Studying note for customizing vim-snippets.
See Github
Module:
1 | snippet [trigger] ["Description"] [index] |
Index:
Index | Description |
---|---|
b | trigger should be in the front of the line |
i | trigger can be inside a word |
w | trigger should be in the edge of two words |
r | trigger can be a regular expression |
A | auto trigger |
Generate a two column table:
1 | snippet tb2 "Create table of two columns" b |
Or generate a code block for bash
1 | snippet bbl "Bashblock" b |
1 | Study note for ROS |
This post record the steps I set up this blog site.
Installation
Use following command to confirm:
1 | $ node -v |
Create and copy SSH key:
1 | $ ssh-keygen -t rsa -C "GitHub email" |
Copy the contents
Go to Github -> Settings and Add SSH key
Confirm the connection:
1 | $ ssh -T git@github.com |
Create Username.github.io(your URL)
1 | $ npm install -g hexo-cli |
Setup a local workspace:
1 | $ git init |
launch local server:
1 | $ hexo cl |
or use following command to specify port:
1 | $ hexo server -p 5000 |
visit http://localhost:4000
Install hexo-developer-git:
1 | $ npm install hexo-deployer-git --save |
edit _config file’s Deployment part:
1 | deploy: |
then run in bash:
1 | $ hexo d |
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
1 | $ hexo new "My New Post" |
More info: Writing
1 | $ hexo server |
More info: Server
1 | $ hexo generate |
More info: Generating
1 | $ hexo deploy |
More info: Deployment