Smart Pet Camera Based on Cat/Dog Detection

1.Project Introduction

1.1 Project Overview

Recording daily moments of beloved pets is a common practice for every pet owner. The "Intelligent Pet Camera Based on Cat-Dog Detection" project uses the UNIHIKER K10 to create a pet beauty camera, making pet life documentation simple and fun. It allows you to capture your pets' adorable moments and track their growth milestones.

UNIHIKER K10 features built-in cat-dog detection. When it detects a cat or dog approaching, it automatically takes a photo and displays the image on the color screen. Users can press buttons to add digital stickers and borders for personalized decoration: press Button A to view captured photos, and Button B to switch between more frames and stickers. Combining hardware AI detection with creative functions, this project helps pet owners effortlessly record their pets' delightful moments.

1.2 Project Functional Diagrams

1.3 Project Video

2.Materials List

2.1 Hardware list

HARDWARE LIST
1 UNIHIKER K10
1 32GB TF Card
1 USB-C Cable
1 TF Card Reader

2.2 Software

Mind+ Graphical Programming Software (Minimum Version Requirement: V1.8.1 RC1.0)

2.3 Basic Mind+ Software Usage

(1) Double click to open the Mind

The following screen will be called up.

Click and switch to offline mode.

(2) Load UNIHIKER K10


Based on the previous steps, then click on "Extensions" find the "UNIHIKER K10" module under the "Board" and click to add it. After clicking "Back" you can find the UNIHIKER K10 in the "Command Area" and complete the loading of UNIHIKER K10.

Then,you need to use a USB cable to connect the UNIHIKER K10 to the computer.

Then, after clicking Connect Device, click COM7-UNIHIKER K10 to connect.

Note: The device name of different UNIHIKER K10 may vary, but all end with K10.

In Windows 10/11, the UNIHIKER K10 is driver-free. However, for Windows 7, manual driver installation is required: https://www.unihiker.com/wiki/K10/faq/#high-frequency-problem.

The next interface you see is the Mind+ programming interface. Let's see what this interface consists of.

Note: For a detailed description of each area of the Mind+ interface, see the Knowledge Hub section of this lesson.

3.Construction Steps

Let's build he Intelligent Pet Camera with programming. We will split it into three into three core tasks to make development clear and manageable:

(1) Capture,Store,and Display Photos

(2) Pets'Face Object Detection

(3) Sticker Decoration

3.1 Task1: Capture,Store,and Display Photos

(1) Material Preparation

To make our pet camera's functionality more realistic, we can prepare a shutter sound effect. Using a TF card and card reader, store the audio file on the TF card. When the A button is pressed to take a photo, the shutter sound will play, mimicking a real camera, as shown below.

(2) Hardware Setup

Afterward, ensure that the UNIHIKER K10 is connected to the computer using a USB cable.Confirm that the UNIHIKER K10 is connected to the computer using a USB cable. Insert the TF card into the card slot of the UNIHIKER K10.

(3) Software Preparation

Make sure that Mind+ is opened and the UNIHIKER board has been successfully loaded. Once confirmed, you can proceed to write the project program.

(4) Writing the Program

STEP One: Call the Cat/Dog Detection

First, we need to use the "enable camera show"command to show the camera feed on the UNIHIKER K10 screen.

Note: For more details about the camera commands, please refer to the Knowledge Hub.

After turning on the camera, we locate the "switch mode face detection" block ,and choose 'cat/dog detection' to switch the camera to pet detection mode.

Note: For details about the face detection command, please refer to the Knowledge Hub.

STEP Two: Capture, Store ,and Display Photos

First, we create a new variable named ā€œcountā€ and use serial numbers to name each captured photo.

Set the initial value of the "count" variable to 0.

Then create a string variable named "picture_name".

We need to use an event callback function. Use the "When Button A Pressed" block, then the "Play TF Card Audio in Background ()" block to simulate the camera shutter sound. Next, use the "Capture and Store to TF Card ()" block to take a photo and save it to the TF card.

We use the join block and the set picture_name block to name the captured photos. The name is formed as "picture" + serial number + ".bmp" (bmp is a type of image storage format).

After taking a photo, we need to display the photo stored on the TF card. Therefore, we use a variable named "flag" to determine whether the photo has been successfully taken. Once the photo is taken, we turn off the camera feed and use the "cache TF card image () at X0Y0" block to show the recently captured photo on the screen.

In this way, we achieve the functionality of capturing, storing photos, and displaying them on the screen. The complete code is shown in the image below:

(5) Run the Program

Check and ensure the UNIHIKER K10 is connected to Mind+. Make sure the IP address is displayed in the ā€œMenu Barā€ section, indicating that the connection is established.

Click the ā€œUploadā€ button in the upper-right corner of the interface.

Program Execution. The camera feed will appear on the screen. When the A button is pressed, a photo will be captured and displayed on the screen, as shown in the image below:

3.2 Task2: Pets'Face Object Detection

(1) Writing the Program

STEP One: Obtain Cat/Dog Detection Data

In the UNIHIKER K10 block store , there is a block that can retrieve the coordinates of the center position of the pet in the frame, as well as the width and height of the pet's face. Additionally, we will create corresponding variables to store the detection data. We will encapsulate this command into the function "pet detection".

First, make a function block named "pet detect".

Create four variables respectively and name them "center_x", "center_y", "h", and "w" in sequence

To obtain the detection data from the captured photo, we need to call the ā€œpet_detect ā€ function within the event callback function "when button A is pressed". This will allow us to retrieve the detection data from the photo taken

STEP Two: Display Cat/Dog Detection Data

To determine the position of the stickers, we need to know the coordinates of the center point. We can display the detection data along with the photo. In the previous step, we stored the detection data in corresponding variables. Now, we can use the "cache text () on line () color ()" blockl to display the data, as shown in the picture below:

The complete program code for the face keypoint detection module is as follows:

(2) Run the Program

Click the ā€œUploadā€ button in the upper-right corner of the interface.

Press the A button and observe the screen. You should see the pet detection data displayed along with the photo.

3.3 Task3: Sticker Decoration

In this task, we need to adjust the position and size of the sticker based on the coordinates of the center point, so that the stickers align with the pet's face.

(1) Material Preparation

To add sticker decorations to the pet photos we take, we need to prepare some sticker and frame images in advance. Use a TF card and a card reader to place the images into the TF card, as shown in the figure below.

(2) Hardware Setup

Afterward, ensure that the UNIHIKER K10 is connected to the computer using a USB cable.Confirm that the UNIHIKER K10 is connected to the computer using a USB cable. Insert the TF card into the card slot of the UNIHIKER K10.

(3) Writing the Program

Let’s take the ā€œhat stickerā€ as an example. We need to adjust the sticker’s position based on the face’s location. To determine the position of the hat sticker, we will use one of the previously obtained center point data as a reference point.

Here, set the x-coordinate of the hat sticker to be the same as the x-position of the center point, and set the y-coordinate of the hat sticker to: the y-coordinate of the center point minus half of the height.

For the beard sticker, set its x-coordinate to match the horizontal coordinate of the center point, and position its y-coordinate slightly below the vertical coordinate of the center point.

To enhance the atmosphere of the photo, we need to add a frame to the image. Additionally, we will set it so that when the B button is pressed, the detection data is cleared from the screen, and the sticker is displayed. To improve the readability of the main program, we will integrate the sticker switching logic into a function called ā€œsticker.ā€The program commands are as follows:

We use random numbers to display stickers and photo frames randomly. When the B button is pressed, a random number is generated. If the number is 1, add photo frame 1 and the hat sticker (for the coordinates of the hat sticker, refer to the analysis above. Based on actual test results, adjustments have been made to compensate for any positional errors).

To return to the photo capture function, we use a wait command. After waiting for three seconds, clear the screen, restart the camera, and reset the flag to 0.

Here's the complete code:

4.Upload the Program and Observe the Effect.

Click Upload button,When the burning progress reaches 100%, it indicates that the program has been successfully uploaded.

STEP:

(1)Press A button to take a photo, and observe the pet image and detection

(2)Press Button B to add random stickers to the photo.

5.Appendix of Materials

icon Pet Camera.zip 772KB Download(0)
License
All Rights
Reserved
licensBg
0