Commit 74509eb9 authored by Chipp Jansen's avatar Chipp Jansen
Browse files

new

parent d8670036
......@@ -66,7 +66,7 @@ If you have `mjpg_streamer` running, then you can view the stream, by openning a
`mjpg_streamer` also supports grabbing single JPGs of the stream. You can grab an image using the `curl` utility, which let's you do HTTP requests (i.e. grab web-pages) from the command line.
curl -o /sdcard/snaps/test.jpg http://localhost:8080/?action=snapshot
curl -o /sdcard/snaps/image.jpg http://localhost:8080/?action=snapshot
This downloads a jpg into the `snaps` directory on the sdcard.
......@@ -86,7 +86,7 @@ The `&` means this program will run in the background, and you can continue typi
`mjpg_streamer` will watch the `snaps` directory for refreshed `test.jpg` to steam. So we will use the `watch` command to re-run the `curl` command once a second (by setting the `-n 1` option).
watch -n 1 curl -o /sdcard/snaps/test.jpg http://localhost:8080/?action=snapshot
watch -n 1 curl -o /sdcard/snaps/image.jpg http://localhost:8080/?action=snapshot
## View your hacky stream
......@@ -119,22 +119,90 @@ Next, we will restart streaming this original image with `mjpg_streamer`:
mjpg_streamer -i "input_v4l2loopback.so -d /dev/video4 --fps 15" -o "output_http.so" > /dev/null 2>&1 &
This is the exactly same command as before, and streams to port 8080. We can refresh the browser to view this smaller stream:
This is the exactly same command as before, and streams to port 8080. We can refresh the browser to view this smaller stream (again, change to your IP address):
http://192.168.1.20:8080/?action=stream
## Modify the stream
Now, we can use imagemagick's `convert` program to manipulate and produce a new image that we can stream.
Now we can modify `image.jpg` to produce a new image to stream. A very handy tool to do this is [Imagemagick](https://imagemagick.org/), which is a power suite of command-line image editing tools.
Let's test this out first with a single image.
Now, we can use imagemagick's [`convert` program](https://imagemagick.org/script/magick.php) to manipulate and produce a new image that we can stream. (Note that on the web documentation the `convert` program has been re-named to just `magick`. We have an older version installed on the cameras so we will use `convert`)
**Step 1** we grab this smaller image using curl (without `watch`) into the `snaps` directory (as before):
Let's test this out with a single image first.
curl -o /sdcard/snaps/test.jpg http://localhost:8080/?action=snapshot
**Step 1** We grab this smaller image using curl (without `watch`) into the `snaps` directory (as before):
Next, we convert this image, we will use the `swirl` option which swirls the center of the image by a number of degrees. Imagemagick's `convert` has SO MANY options to manipulate the image (such as drawing etc...).
curl -o /sdcard/snaps/image.jpg http://localhost:8080/?action=snapshot
convert /sdcard/snaps/test.jpg -swirl 60 /sdcard/stream/out.jpg
**Step 2** We convert this image. We will use the [`swirl` option](https://imagemagick.org/script/command-line-options.php#swirl) which swirls the center of the image by a number of degrees. Imagemagick's `convert` has [SO MANY options](https://imagemagick.org/script/command-line-options.php) to manipulate the image. For example, you can [draw](https://imagemagick.org/Usage/draw/) on the images.
Finally, we run our new `mjpg_streamer` which will stream images from a separate
convert /sdcard/snaps/image.jpg -swirl 60 /sdcard/stream/out.jpg
**Step 3** We will start a new `mjpg_streamer` which will stream images from the `stream` directory (Note that before we streamed from the original images directory).
mjpg_streamer -i "input_file.so -f /sdcard/stream" -o "output_http.so -p 8081" > /dev/null 2>&1 &
Now, let's view this stream (on port 8081):
http://192.168.1.20:8081/?action=stream
You might not see anyting at first. With the browser open to this url, run the commands from **Step 1** and **Step 2** again. The image should show up now.
## Put it all together
Now that we need to run two commands, we will write a small script in `/sdcard` that we will run every second with `watch`. The camera has `nano` which is a simple text editor (there is also `vi` for those who prefer that). In the directory `/sdcard` run:
nano swirl.sh
Now you can copy this script:
#!/bin/sh
curl -so /sdcard/snaps/image.jpg http://localhost:8080/?action=snapshot
convert /sdcard/snaps/image.jpg -swirl 60 /sdcard/stream/out.jpg
You save by hitting `control-O` (the letter o), hitting Enter to accept. Then `control-X` (the letter x) to exit.
Next, we need to make the script runnable as an executable (i.e. a program):
chmod +x swirl.sh
Now we can run:
watch -n 1 ./swirl.sh
Which runs the script every second. But note that there is a delay on the camera to `curl` and `convert` the image!
## Adding Randomness
Right now the swirl is the same. Randomness can add some interest to the converted image. We can use the `RANDOM` variable in our script to change the degree of the swirl.
First, we will start with a copy (`rswirl.sh`) of our script:
cp swirl.sh rswirl.sh
With nano (`nano rswirl.sh`) we can edit the swirl degree with `RANDOM%360`, which is the random number mod 360. (Mod is division but you keep the remainder only. It's an easy way to create random numbers in a certain range of values 0 to 360).
Here is the `rswirl.sh` script:
#!/bin/sh
curl -so /sdcard/snaps/image.jpg http://localhost:8080/?action=snapshot
convert /sdcard/snaps/image.jpg -swirl $((RANDOM%360)) /sdcard/stream/out.jpg
## Play with the options
There are so many options with `convert`. Try picking one and modifying the image somehow. For example you can tint the image a randome intensity of blue.
Here's a tip. Create a new script with every modification that you are experimenting with.
For example, create a new script (copy the old one) called someting like `rtint.sh`:
#!/bin/sh
curl -so /sdcard/snaps/image.jpg http://localhost:8080/?action=snapshot
convert /sdcard/snaps/image.jpg -fill blue -tint $((RANDOM%100)) /sdcard/stream/out.jpg
## Further Ideas and Challenges
***Congratulations!!!*** You have successfully set-up your own modified camera image stream. Although, it is slow, it
* Idea
* Idea
* Idea
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment