This project implements a TCP server (uqfacedetect) and client (uqfaceclient) for face detection and replacement in images using OpenCV. The server supports multiple concurrent clients, connection limiting, and statistics reporting via SIGHUP. Communication uses a custom binary protocol.
- uqfaceclient: Sends image detection/replacement requests to the server and saves the response.
- uqfacedetect: Multi-threaded server that processes requests, detects faces, and optionally replaces faces in images.
uqfaceclient.c— Client program source codeuqfacedetect.c— Server program source codeprotocol.c/h— Shared protocol implementation for client/server communicationMakefile— Build instructionsspec.txt— Assignment specification (converted from PDF)README.md— Project documentation
- Face detection in images using Haar cascade classifiers (OpenCV)
- Face replacement: detected faces can be replaced with a provided image
- Multi-threaded server: handles multiple clients simultaneously
- Connection limiting: restricts number of concurrent clients (configurable)
- SIGHUP statistics: server reports statistics to stderr on SIGHUP
- Robust error handling and protocol compliance
Run the following command in the project root directory:
makeThis will build both uqfaceclient and uqfacedetect.
./uqfacedetect connectionlimit maxsize [portnumber]connectionlimit: Maximum simultaneous client connections (0 for unlimited, max 10000)maxsize: Maximum image size in bytes (0 for 2^32-1)portnumber: Port to listen on (optional, ephemeral if omitted)
Example:
./uqfacedetect 5 10000000 2310On startup, the server prints the actual port number to stderr.
./uqfaceclient port [--detectfile filename] [--output filename] [--replacefile filename]port: Server port or service name for client connection--detectfile: Input image file for face detection (optional, reads from stdin if omitted)--replacefile: Image file to replace detected faces (optional)--output: Output file for result (optional, writes to stdout if omitted)
Examples:
./uqfaceclient 2310 --detectfile input.jpg --output result.jpg
./uqfaceclient 2310 --detectfile input.jpg --replacefile face.png --output result.jpg
./uqfaceclient 2310 < input.jpg > result.jpgClient and server communicate using a custom binary protocol:
| Field | Size (bytes) | Description |
|---|---|---|
| Prefix | 4 | 0x23107231 (little-endian) |
| Operation | 1 | 0: detect, 1: replace, 2: output, 3: error |
| Image1 Size | 4 | Size of image 1 or error message |
| Image1 Data | M | Image data or error message |
| Image2 Size | 4 (replace) | Size of image 2 (only for replace) |
| Image2 Data | N (replace) | Replacement image data (only for replace) |
See spec.txt for full protocol details.
- Invalid command line: prints usage and exits with status 7 (server) or 12 (client)
- File open errors: prints error and exits with status 10/18
- Connection errors: prints error and exits with status 5/14
- Protocol errors: prints error and exits with status 8/15
- All error messages strictly follow the assignment specification
- OpenCV 3.4.6 (server only, required for image processing)
- gcc (recommended environment: moss.labs.eait.uq.edu.au)
- POSIX threads and semaphores
- Follows CSSE2310/CSSE7231 C programming style guide (see spec.txt)
- No global variables, no functions >100 lines, no forbidden functions (see spec.txt)
- All protocol logic is implemented in
protocol.c/h - All memory is freed before exit
- Test with provided demo programs (
demo-uqfaceclient,demo-uqfacedetect) - Use netcat for protocol testing
- SIGHUP statistics can be triggered with
kill -HUP <pid> - See
spec.txtfor detailed test cases and requirements
- Assignment specification: see
spec.txt - OpenCV documentation: https://docs.opencv.org/3.4.6/
- Example images:
/local/courses/csse2310/resources/a4/testimages/(on moss)
For questions, please contact course staff or refer to the course discussion forum.