Face Tracking
Our face detection uses Tencent's ncnn, uses the SP7021 PWM module for servo control, and rootfs uses the image of the Raspberry Pi.
Configure the kernel
We need to use PWM, so the kernel enables PWM driver, set the right pins in DTS。
Enable the PWM driver
plus1@ubuntu:~/SP7021_4.19/linux/kernel$ make menuconfig
Device Drivers->Pulse-Width Modulation (PWM) Support->SP7021 PWM support
Configure the output pin of pwm in dts
linux/kernel/arch/arm/boot/dts/sp7021-common.dtsi
modify the pwm device node,
pwm: pwm@0x9c007a00 {
#pwm-cells = <2>;
compatible = "sunplus,sp7021-pwm";
reg = <0x9c007a00 0x80>;
clocks = <&clkc DISP_PWM>;
resets = <&rstc RST_DISP_PWM>;
};
add the pin contrl information,
pwm: pwm@0x9c007a00 {
#pwm-cells = <2>;
compatible = "sunplus,sp7021-pwm";
reg = <0x9c007a00 0x80>;
clocks = <&clkc DISP_PWM>;
resets = <&rstc RST_DISP_PWM>;
pinctrl-names = "defalut";
pinctrl-0 = <&pins_pwm0>;
};
seach the pctl device node,
pctl: pctl@0x9C000100 {
compatible = "sunplus,sp7021-pctl";
reg = <0x9C000100 0x100>, <0x9C000300 0x80>, <0x9C000380 0x80>, <0x9C0032e4 0x1C>, <0x9C000080 0x20>;
gpio-controller;
#gpio-cells = <2>;
interrupt-parent = <&intc>;
interrupts =
<120 IRQ_TYPE_LEVEL_HIGH>,
<121 IRQ_TYPE_LEVEL_HIGH>,
<122 IRQ_TYPE_LEVEL_HIGH>,
<123 IRQ_TYPE_LEVEL_HIGH>,
<124 IRQ_TYPE_LEVEL_HIGH>,
<125 IRQ_TYPE_LEVEL_HIGH>,
<126 IRQ_TYPE_LEVEL_HIGH>,
<127 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clkc GPIO>;
resets = <&rstc RST_GPIO>;
pins_uart0: pins_uart0 {
sppctl,groups = "UA0";
sppctl,function = "UA0";
};
we use the 8, 9 pin for the pwm output pin, add the pwm pin mux information into the pctl node.
pctl: pctl@0x9C000100 {
compatible = "sunplus,sp7021-pctl";
reg = <0x9C000100 0x100>, <0x9C000300 0x80>, <0x9C000380 0x80>, <0x9C0032e4 0x1C>, <0x9C000080 0x20>;
gpio-controller;
#gpio-cells = <2>;
interrupt-parent = <&intc>;
interrupts =
<120 IRQ_TYPE_LEVEL_HIGH>,
<121 IRQ_TYPE_LEVEL_HIGH>,
<122 IRQ_TYPE_LEVEL_HIGH>,
<123 IRQ_TYPE_LEVEL_HIGH>,
<124 IRQ_TYPE_LEVEL_HIGH>,
<125 IRQ_TYPE_LEVEL_HIGH>,
<126 IRQ_TYPE_LEVEL_HIGH>,
<127 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clkc GPIO>;
resets = <&rstc RST_GPIO>;
pins_pwm0: pins_pwm0{
sppctl, pins <SP7021_IOPAD(8, SP7021_PCTL_G_PMUX, MUXF_PWM0, 0)
SP7021_IOPAD(9, SP7021_PCTL_G_PMUX, MUXF_PWM1, 1)>
}
pins_uart0: pins_uart0 {
sppctl,groups = "UA0";
sppctl,function = "UA0";
};
The 8,9 pin in the demo board v3.
Now how th compile source code ,please refer:How to build and install SP7021 Linux image to run Raspbian on SD card .
Install related components
in the raspbian ubuntu, install the camke and libopencv-dev
sudo apt install cmake libopencv-dev
Download ncnn source code
git clone --depth=1 https://github.com/tencent/ncnn.git
download the attachment file ,the attachment file is the face tracking demo code.
Unzip the file to ncnn/example
excute the ./build script for build the mtcnn_new demo
sudo b/example/mtcnn_new <camera_id>
<camera_id> is v4L2 video device, the usb camera in the raspberry is video 0, so
sudo b/example/mtcnn_new 0