Skip to content

Commit

Permalink
add syntax highlighting to readmes
Browse files Browse the repository at this point in the history
  • Loading branch information
gunarp committed Sep 15, 2020
1 parent ffe3b95 commit 8010b99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Part 3/publisher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This comment isn't necessary on every computer, but you should add it in if ther


Defines the publisher and sets the linear and angular velocity to the default value
```
```Python
def move():
# Create a new node
velocity_publisher = rospy.Publisher('/wheely_boi/wheely_boi/cmd', Twist, queue_size=10)
Expand All @@ -28,7 +28,7 @@ def move():
Our publisher constantly advertises the state of the robot, so we use a while loop.

In our loop, we read in keyboard input from the user and update our geometry message t accordingly.
```
```Python
while not rospy.is_shutdown():
key = curses.wrapper(getch_c)
if (key == ord('w')):
Expand All @@ -54,7 +54,7 @@ while not rospy.is_shutdown():


The getch_c method takes input from our keyboard and returns the value
```
```Python
def getch_c(stdscr):
# do not wait for input when calling getch
stdscr.nodelay(1)
Expand Down
16 changes: 8 additions & 8 deletions Part 4/controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To avoid this, we'll create a new thread which is dedicated to streaming the vid

Now let's jump into the code.

```
```Python
from threading import Thread
from tools.VideoStream import VideoStream

Expand All @@ -27,7 +27,7 @@ stream.start()

This chunk of code creates a new VideoStream object, and that's where the threading magic happens.

```
```Python
class VideoStream(Thread):
def __init__(self, src=0):
Thread.__init__(self)
Expand All @@ -44,7 +44,7 @@ It's a little hidden in this function but all our digit recognition happens with
`find_label()` is a function which lives in `cam_util.py`, a utility file which contains some useful functions.

Let's walk through a call to `find_label()`:
```
```Py
final_img = img_to_mnist(frame)

def img_to_mnist(frame):
Expand All @@ -61,13 +61,13 @@ First we'll do some filtering on our input frame with `img_to_mnist()`. Recall t
2. `cv2.GaussianBlur`: Next we'll apply a blur to the image to reduce noise. This is helpful as it'll reduce the amount of contours we'll have to sift through later.
3. `cv2.adaptiveThreashold`: This function will make our image close to black and white. It's responsible for making our image look like an MNIST data point.

```
```Python
contours, _ = cv2.findContours(final_img.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
```
Next, we'll apply contours and identify the boundaries in our image. This will hopefully give us an outline of our handwritten digit if `img_to_mnist` did its job correctly.

```
```py
rects = [cv2.boundingRect(contour) for contour in contours]
rects = [rect for rect in rects if rect[2] >= 3 and rect[3] >= 8]

Expand All @@ -79,7 +79,7 @@ rect = rects[max_rect_i]
```
Here we are singling out the largest rectangle present in the image (if there is one) and drawing a bounding box around it.

```
```py
mnist_frame = extract_digit(frame, final_img, rect, pad = 15)

def extract_digit(frame, img, rect, pad = 10, SIZE=28):
Expand All @@ -94,7 +94,7 @@ def extract_digit(frame, img, rect, pad = 10, SIZE=28):
```
Given the predetermined rectangle and its contents, the image is cropped and resized to better fit our model using the `extract_digit()` method. Smaller images are ignored.

```
```py
model_in = torch.tensor(mnist_frame).float()
# lift model into appropriate dim
model_in = model_in.unsqueeze(0).unsqueeze(0)
Expand All @@ -116,7 +116,7 @@ This inaccuracy most likely comes from the cropped images not looking enough lik
Our publishing is essentially the same as it was in `key_in.py`, but with different signals.

In our while loop, we'll simply tell ROS to publish a message according to what our model decides the output should be.
```
```py
publish(find_label(frame, network), t, velocity_publisher)

def publish(signal, t, velocity_publisher):
Expand Down

0 comments on commit 8010b99

Please sign in to comment.