add some code
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(conv2d)
|
||||
@@ -0,0 +1,57 @@
|
||||
# 2D convolution Example
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This example demonstrates how to use 2D convolution dspi_conv_f32 from esp-dsp library. Example does the following steps:
|
||||
|
||||
1. Initialize the input arrays
|
||||
2. Calculate 2D convolution of two images
|
||||
|
||||
The example reproduce the Matlab code:
|
||||
|
||||
```
|
||||
A = ones(8);
|
||||
B = ones(4);
|
||||
Csame = conv2(A,B, "same")
|
||||
|
||||
```
|
||||
|
||||
|
||||
## How to use example
|
||||
|
||||
### Hardware required
|
||||
|
||||
This example does not require any special hardware, and can be run on any common development board.
|
||||
|
||||
### Configure the project
|
||||
|
||||
Under Component Config ---> DSP Library ---> DSP Optimization, it's possible to choose either the optimized or ANSI implementation, to compare them.
|
||||
|
||||
### Build and flash
|
||||
|
||||
Build the project and flash it to the board, then run monitor tool to view serial output (replace PORT with serial port name):
|
||||
|
||||
```
|
||||
idf.py -p PORT flash monitor
|
||||
```
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
|
||||
|
||||
## Example output
|
||||
|
||||
Here is an typical example console output.
|
||||
|
||||
```
|
||||
I (305) main: Start Example.
|
||||
I (305) main: 2D Convolution reuslt.
|
||||
[ 0 .. 8, 0]: 9, 12, 12, 12, 12, 12, 9, 6,
|
||||
[ 0 .. 8, 1]: 12, 16, 16, 16, 16, 16, 12, 8,
|
||||
[ 0 .. 8, 2]: 12, 16, 16, 16, 16, 16, 12, 8,
|
||||
[ 0 .. 8, 3]: 12, 16, 16, 16, 16, 16, 12, 8,
|
||||
[ 0 .. 8, 4]: 12, 16, 16, 16, 16, 16, 12, 8,
|
||||
[ 0 .. 8, 5]: 12, 16, 16, 16, 16, 16, 12, 8,
|
||||
[ 0 .. 8, 6]: 9, 12, 12, 12, 12, 12, 9, 6,
|
||||
[ 0 .. 8, 7]: 6, 8, 8, 8, 8, 8, 6, 4,
|
||||
```
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "conv2d_main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include "esp_dsp.h"
|
||||
#include "dsp_tests.h"
|
||||
|
||||
static const char *TAG = "main";
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Start Example.");
|
||||
|
||||
int max_N = 100;
|
||||
|
||||
float *data1 = (float *)memalign(16, max_N * sizeof(float));
|
||||
float *data2 = (float *)memalign(16, max_N * sizeof(float));
|
||||
float *data3 = (float *)memalign(16, max_N * sizeof(float));
|
||||
|
||||
image2d_t image1 = {data1, 1, 1, 8, 8, 8, 8}; // Image 8x8
|
||||
image2d_t image2 = {data2, 1, 1, 4, 4, 4, 4}; // Image 4x4
|
||||
image2d_t image3 = {data3, 1, 1, 10, 10, 0, 0}; // Image 10x10
|
||||
|
||||
for (int i = 0 ; i < max_N ; i++) {
|
||||
data1[i] = 0;
|
||||
data2[i] = 0;
|
||||
data3[i] = 0;
|
||||
}
|
||||
|
||||
for (int y = 0 ; y < image1.stride_y / image1.step_y ; y++) {
|
||||
for (int x = 0 ; x < image1.stride_x / image1.step_x ; x++) {
|
||||
data1[y * image1.stride_x * image1.step_y + x * image1.step_x] = 1;
|
||||
}
|
||||
}
|
||||
for (int y = 0 ; y < image2.stride_y / image2.step_y ; y++) {
|
||||
for (int x = 0 ; x < image2.stride_x / image2.step_x ; x++) {
|
||||
data2[y * image2.stride_x * image2.step_y + x * image2.step_x] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
dspi_conv_f32(&image1, &image2, &image3);
|
||||
|
||||
ESP_LOGI(TAG, "2D Convolution reuslt.");
|
||||
|
||||
for (int y = 0 ; y < image3.size_y; y++) {
|
||||
printf("[%2i .. %2i, %2i]: ", 0, image3.size_x, y);
|
||||
for (int x = 0 ; x < image3.size_x; x++) {
|
||||
printf("%2.0f, ", data3[y * image3.stride_x * image3.step_y + x * image3.step_x]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
free(data1);
|
||||
free(data2);
|
||||
free(data3);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
dependencies:
|
||||
espressif/esp-dsp:
|
||||
override_path: "../../../"
|
||||
version: "*"
|
||||
@@ -0,0 +1,4 @@
|
||||
# This file was generated using idf.py save-defconfig. It can be edited manually.
|
||||
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x9000
|
||||
Reference in New Issue
Block a user