Please enable JavaScript to view this site.

Waijung 2 User Guide

Navigation: Zynq-7000 target > Tutorials > Advanced tutorials

Tutorial 3: Image classification using camera feed in Zynq-7000

Scroll Prev Top Next More

Introduction

This tutorial will be an extend version of tutorial 2 which will be using the video stream from the Pcam 5C camera instead of a still image. The image classification algorithm will be same as in tutorial 2 and the only difference is the input image source. This tutorial will first continue with the hardware designing in Vivado design suite and then it will focus on implementing the Simulink model.

Make the hardware design using Vivado

The hardware design for this tutorial will not be created from scratch. We are going to use the Pcam 5C demo from Digilent. We can use the same hardware design as in the demo and get the image frames to the PS in Zybo 7z20.

1.Download the Vivado design project Zybo-Z7-20-Pcam-5C-hw.zip and extract the zip file.

2.Open the Vivado design suite and go to Open Project

zynq7000_advanced_tutorial3_1

3.Browse to the hw folder inside the project folder that you downloaded and extracted and open the hw.xpr project file

zynq7000_advanced_tutorial3_2

4.Once the project is opened successfully open the block design to see the existing block design

zynq7000_advanced_tutorial3_3
zynq7000_advanced_tutorial3_4    

5.Following IPs are the main components of reading the camera, send the frame buffers to the PS and pass them to the HDMI TX

zynq7000_advanced_tutorial3_5

a.Reading Pcam 5C through the MIPI interface

b.Converting Bayer image buffer to RGB

c.Gamma correction

d.AXI VDMA which is used to read the AXI stream data (image buffer) and save it in the DDR memory through PS using AXI memory map

e.Access the image buffer in DDR and use it for further process in PS (eg. use as an input to the image classifier algorithm)

6.Next, generate the Bitstream by clicking on Generate Bitstream. Then click Yes to continue

zynq7000_advanced_tutorial3_6

7.Once the process is finished, click Cancel to the popup dialog box.  Next, the remaining task is to export the hardware design file from Vivado. For that, go to File Export Export Hardware. Click Next on the wizard. Next, select Include Bitstream from the selection and click Next. Then give a proper name for the hardware design file and the location to export.

zynq7000_advanced_tutorial3_7

8.Then click on Next and click Finish

Create the Simulink Model

1.Open Matlab and change the current folder to the folder that you want to create the project. Then open Simulink, create a blank model and save it with a proper name

zynq7000_advanced_tutorial3_8

2.Import following blocks to the blank model

zynq7000_advanced_tutorial3_9

a.Waijung 2 Target Setup block

b.Basic Custom Code

c.Matrix Concatenate

d.Image Classifier block

e.To String block

f.Compose String block

g.String to ASCII block

h.Print block

2.Modify following mask parameters of following blocks

a.Waijung 2 Target Setup block

i.Waijung 2 tab

1.Project: C++

2.Xilinx tool path: Change the path according to your installed location of Xilinx tools

zynq7000_advanced_tutorial3_10

ii.ZYNQ7000 tab

1. Custom XSA file path: Location of the xsa file which you exported above using Vivado

2.Stack size: 0x3000000

3.Heap size: 0x9900000

zynq7000_advanced_tutorial3_11

b.Basic Custom Code

i.Download the C code library for camera and extract. Then copy it to the place where the Simulink mode is

zynq7000_advanced_tutorial3_12

ii.Mask display name: Pcam 5C

iii.Input port definition:  Delete all

iv.Output port definition:

Label

Type

Dimentions

R

uint8

1280x720

G

uint8

1280x720

B

uint8

1280x720

v.Source file selection

1.File path: pwd,"custom_lib"

2.File names: AXI_VDMA.c,AXI_VDMA.h,cam_init.c,cam_init.h,OV5640.c,OV5640.h,PS_GPIO.c,

PS_GPIO.h,PS_IIC.c,PS_IIC.h,ScuGicInterruptController.h,VideoOutput.c,VideoOutput.h

vi.Initial function call string: init_cam();

vii.Output function call string: read_cam_rgb(out1, out2, out3);

zynq7000_advanced_tutorial3_13zynq7000_advanced_tutorial3_14

c.Matrix Concatenate

i.Number of inputs: 3

ii.Concatenate dimension: 3

zynq7000_advanced_tutorial3_15

d.Image Classifier block

i.Network: Network from MATLAB function

ii.MATLAB function: mobilenetv2

zynq7000_advanced_tutorial3_16

e.Compose String block

i.Format: "label: %s\r\n"

zynq7000_advanced_tutorial3_17

f.String to ASCII block

i.Output vector size: 64

zynq7000_advanced_tutorial3_18

g.Print block

i.String Input Type: Character Vector

zynq7000_advanced_tutorial3_19

3.Connect each block as follows

zynq7000_advanced_tutorial3_20

4.Change the following Model Configuration parameters (goto MODELING tab Model Configuration parameters )which are related to the Image Classifier block

a.Code Generation Interface Deep learning

i.Target Library: ARM Compute

ii.ARM Compute Library version: 20.02.1

iii.ARM Compute Library architecture: armv7

b.Code Generation Interface Software environment

i.variable-size signals: Enable

zynq7000_advanced_tutorial3_21

5.Save the Simulink model. Then go to APPS Embedded Coder. To build the Simulink model go to C CODE Build. Then connect the Zybo 7z20 board to the computer using the USB cable and connect the HDMI TX interface to a monitor. Turn on the board

zynq7000_advanced_tutorial3_22
zynq7000_advanced_tutorial3_23

6.While the Simulink model is building, a dialog box will be popped up asking to copy the bin files from the opened folder to the SD card

zynq7000_advanced_tutorial3_24

7.First, plug the micro SD card to the Computer and copy all the .bin files from the opened folder. A folder will be opened automatically when the above dialog box is popped up

zynq7000_advanced_tutorial2_28

8.After all the .bin files are copied, plug the SD card to the Zybo 7z20 board and press Continue to the above dialog box so that it will continue the build process

zynq7000_advanced_tutorial2_29

9.After the build process is successfully finished. Open the Serial Monitor with the correct COM port and set the Baudrate to 115200

zynq7000_advanced_tutorial3_26
zynq7000_advanced_tutorial3_28

10.Point the camera to any object that you need to checkout. The most suitable label will printout in the serial monitor. Followings are the sample results.

a.Box

zynq7000_advanced_tutorial3_29
zynq7000_advanced_tutorial3_30

b.Remote controller

zynq7000_advanced_tutorial3_31zynq7000_advanced_tutorial3_32

Resources

Simulink model: tutorial_3.slx

XSA file: tutorial3.xsa

 

 

Copyright 2024 Aimagin Co.,Ltd. Rev.1680