Have you ever wondered how machines gain vision and perceive the world like humans? As a core application of machine vision, object recognition technology enables devices to distinguish objects accurately, achieving efficient interaction from visual perception to intelligent response.
In this lesson, we'll build a smart pet camera based on the UNIHIKER K10, unlocking functions like automatic pet recognition, photo capture, and decoration with custom frames and stickers. Then you'll intuitively experience its ingenious daily-life applications.
Project Objectives
Knowledge Objectives
1.Understand object recognition
2.Use UNIHIKER K10 cat/dog recognition
Practical Objective
Build a smart pet camera with the UNIHIKER K10 board's built-in cat and dog detection. When a cat or dog approaches, press Button A to take a photo and view it on the color screen immediately. Press Button B to switch stickers and add personalized decorations to the photo.

Materials List
Preparations
Hardware
Insert the TF card into the UNIHIKER K10's corresponding slot, and then connect the UNIHIKER K10 to the computer via a USB cable.

Software
Open Mind+, switch to“Upload Mode”, connect the UNIHIKER K10 as shown in the figure below, and load the UNIHIKER K10 library.

Hands-on Practice
Next, we'll use the UNIHIKER K10 camera's cat/dog detection function to make a smart pet camera via three tasks: pet recognition, photo capture, and sticker & photo frame switching.
Task 1: Pet Recognition
First, we'll learn to add block words for pet recognition and output results via the serial port.
Task 2: Recognize and Display Stickers
Then, press Button A to capture an image and identify the pet's coordinate info in the photo. Press Button B to add corresponding stickers to the photo based on the identified coordinates. Pressing Button A again lets you retake the photo.
Task 3: Camera Function Improvement
Last, we'll continue to optimize camera functions. We'll add light prompts and sound effects during photo-taking to attract the pet's attention.
Task 1: Pet Recognition
Code
Pet recognition relies on the on-board camera, whose specific position is shown below:

First, to display the camera feed on the screen, “(enable) camera show” block under “Screen”of UNIHIKER K10 is required, as shown below:

To determine pet detection, switch the camera to “Cat/Dog Detection” mode first before judgment. This uses blocks under“AI”of UNIHIKER K10: “switch mode (face detection)” and “detected (face)?”, as shown below.

Finally, output the judgment result through the serial port.
The complete reading code is shown below:

Run the Code
Click the“Upload”button, wait for upload completion, then open the serial port. Aim the on-board camera at different objects respectively and observe the serial port output results.

Note: Only face and cat face detection will overlay recognition boxes on the screen. When detecting, hold the screen vertically (Type-C port upward); detection will fail in landscape orientation.
Code Review
Category | Blocks | Function |
![]() | Show/Disable Camera. Use this command to display or not display the camera screen on the K10 screen. | |
![]() | The block is used to switch between machine vision algorithm modes and to superimpose the recognition frame on the screen. Among them, four algorithm modes can be selected: face detection, cat and dog detection, motion detection and QR code recognition. | |
![]() | In the corresponding algorithmic mode, it is used to determine whether a face/cat/dog/movement/QR code is detected or not. |
Task 2: Recognize and Display Stickers
Code
To save captured photos to the TF card, use "capture photo to TF card (“photo.bmp”)” block under “Screen”of “UNIHIKER K10”, as shown below.

Meanwhile, press Button A once to capture a photo; press it again to return to the camera preview and retake. Determine the function of pressing Button A by setting the "flag" variable. The logic is as follows:

To enable continuous shooting and saving of multiple photos, we'll name photos "picture+serial number.bmp". The "serial number" is controlled by setting variable "number", whose value increments by 1 each time a photo is taken.
Note: When taking photos and saving images with UNIHIKER K10, only BMP format is supported for storage and display.
The corresponding code is as follows:

To implement sticker switching, you need to store the sticker images on the TF card in advance (the sticker names are shown in the figure below).

The difficulty of adding stickers is determining their placement. We can refer to the green recognition box on the screen during shooting to roughly locate the pet's head and then confirm the sticker placement accordingly.
Determine the pet's head center coordinates (x, y), width (w), and height (h) based on the recognition box. Combine these four parameters with the screen coordinate system to roughly calculate the sticker display position and then implement the sticker display function, as shown below:

To record the four data values, set four corresponding variables to store position information. To read specific position information, use“get cat/dog face attributes (length)”block under“AI”of UNIHIKER K10, as shown below:

The detected data can be displayed synchronously when the captured photo is shown on the screen. The corresponding program is as follows:

Next, determine the coordinates of the sticker based on the acquired data and the intended placement position of the sticker (as shown below).

The coordinates of other stickers can be determined independently by function.
To implement random sticker switching, set the variable "sticker" and generate a random number between 1 and 10. The corresponding code is as follows:

To make the code more organized, we can encapsulate "reading the coordinates of the pet's head" and "sticker switching" into two functions: detect and sticker. We only need to call the corresponding function names in the main program and the callback function section. The program is shown below.


The complete reading code is shown in the figure below:

Run the Code
Click the“Upload”button and wait for the upload to finish. Aim the camera at a pet and press Button A to take a photo.
Then, the screen will show the captured image and read coordinates. Next, press Button B to randomly add and switch stickers and photo frames.
Finally, press Button A again for the camera preview to retake photos.

Code Review
Category | Blocks | Function |
![]() | Save the current frame captured by the camera and store it in the TF card. | |
![]() | Get the key point data of the detected cat face containing length, width, centre point x, centre point y. |
Task 3: Camera Function Improvement
Code
First, to make the shooting more realistic, we play the shutter sound effect "shutter_sound.wav" synchronously when pressing Button A to take a photo. This sound effect should be stored on the TF card beforehand.

Secondly, press Button A to take a photo. The RGB light will flash synchronously to attract the pet's attention and achieve a better shooting effect. All the above functions can be modified based on the program of Task 2. The modified parts are as follows:

Run the Code
Click the“Upload”button and wait for the upload to complete. Press Button A and Button B respectively to achieve the target functions.
Knowledge Base
Next, let's learn and summarize the hardware knowledge used in this lesson.
The Concept of Object Recognition
Object recognition is an important part of machine vision technology in AI. Its core is to enable devices to identify specific objects.
Its basic logic is as follows: The UNIHIKER K10 acquires surrounding environment image information through its built-in camera. Then, using a pre- set algorithm model, it analyzes and matches object features in the image. Finally, it determines the existence of the target object and can obtain key information such as the object's position and size, which supports the execution of subsequent preset functions.
The camera acquires image information.

In short, this technology enables the device to distinguish objects. For instance, in this project, UNIHIKER K10 uses object recognition to identify pets in the frame and trigger photo-taking. It also locates and measures the pet’s face with a recognition box for later decoration-adding. This allows the camera to shift from simple image-capturing to performing practical tasks based on recognition results, achieving the intelligent transformation from perception to response.
Object recognition accurately locks onto specific objects, acquires key data like position and size, and automatically triggers preset functions after recognition to achieve an intelligent "perception-response" connection.
Based on these characteristics, object recognition is widely used in fields like smart living, security and surveillance, logistics and retail, and mobility.
Challenge Task
When pet owners use a homemade smart pet camera to take photos, the pet is often too far or close, resulting in poor -quality photos. Owners hope the camera can give intuitive feedback based on the pet's face distance to remind them to adjust position and distance. This feedback is shown by the RGB light's on/off status, enhancing the camera's interactivity and practicality.
Tip: Use the width or height of the pet's face from the camera recognition box to judge the distance.
(1)When the distance is appropriate, the RGB light turns off.
(2)When the distance is too far, the RGB light lights up red.
(3)When the distance is too close, the RGB light lights up yellow.
Press Button A to take a photo only after the distance is appropriate.
Part of the reference code is as follows:
















![[Spanish ver.] HuskyLens Cámara Inteligencia Artificial](https://dfimg.dfrobot.com/nobody/makelog/902f49d1d2eb94077e1ba7d8b652cee6_224x164.jpg)