Introduction to Python programming for the course TPK4128 Industrial Mechatronics at the Department of Mechanical and Industrial Engineering, NTNU, Norwegian University of Science and Technology
The task is to build a Python module that implements a socket server that fetches images from a webcam and sends it over a TCP/IP or UDP socket when it gets a request from a client.
- Install Ubuntu in a virtual machine, e.g., VirtualBox.
- Mount the the integrated webcam into the Ubuntu VM.
- Make sure the virtual machine is not running and your webcam is not being used.
- Bring up the main VBox window and in the details tab for your virtual machine click USB.
- Make sure "Enable USB Controller" is selected. Also make sure that "Enable USB 2.0 (EHCI) Controller" is selected too.
- Click the "Add filter from device" button (the cable with the '+' icon).
- Select your device from the list.
- Now click OK and start your VM.
- Open a terminal and execute the command
ls /dev
. You should now seevideo0
in the output. Note that you might need to add the camera manually from the top menu: Devices > Webcams > NameOfYourCamera - Install the
tpk4128
module (with dependencies):
mkdir -p ~/tpk4128_ws/src
cd ~/tpk4128_ws/src
git clone https://github.com/tingelst/tpk4128-industrial-mechatronics.git
pip3 install ./tpk4128-industrial-mechatronics # Use pip for Python 2
- Implement the
Camera
class in the filetpk4128/camera_opencv.py
. See https://docs.opencv.org/3.4/dd/d43/tutorial_py_video_display.html for a tutorial on how to open a video stream from a webcam. - Implement the
scripts/run_client_opencv.py
script, that sends a message overlocalhost
to a server implemented in thescripts/run_server_opencv.py
script. - Open a new terminal and execute the
run_server_opencv.py
script. - Open a new terminal and execute the
run_client_opencv.py
script. You should now see a live stream from your webcam. - If time permits, work together in pairs and try to get the above system to work between two remote machines.