add filter and ota(model and cfg file)

it is OK
This commit is contained in:
xuedongliang 2021-09-07 10:10:25 +08:00
commit 6fc420e6a3
33 changed files with 2260 additions and 3 deletions

View File

@ -308,7 +308,7 @@ static void *thread_instrusion_detect_entry(void *parameter)
instrusion_detect_rl.input = output;
region_layer_run(&instrusion_detect_rl, &instrusion_detect_info);
/* display result */
#ifdef BSP_USING_LCD
for (int instrusion_cnt = 0; instrusion_cnt < instrusion_detect_info.obj_number; instrusion_cnt++) {
// draw_edge((uint32_t *)showbuffer, &instrusion_detect_info, instrusion_cnt, 0xF800,
// (uint16_t)sensor_output_size[1],
@ -321,6 +321,7 @@ static void *thread_instrusion_detect_entry(void *parameter)
if (0 != instrusion_detect_info.obj_number) {
printf("\n");
}
#ifdef BSP_USING_LCD
lcd_draw_picture(0, 0, (uint16_t)sensor_output_size[1], (uint16_t)sensor_output_size[0], (unsigned int *)showbuffer);
#endif
usleep(1);

View File

@ -5,4 +5,6 @@ menuconfig SUPPORT_KNOWING_FRAMEWORK
if SUPPORT_KNOWING_FRAMEWORK
source "$APP_DIR/Framework/knowing/tensorflow-lite/Kconfig"
source "$APP_DIR/Framework/knowing/kpu-postprocessing/Kconfig"
source "$APP_DIR/Framework/knowing/filter/Kconfig"
source "$APP_DIR/Framework/knowing/ota/Kconfig"
endif

View File

@ -0,0 +1,34 @@
menuconfig USING_KNOWING_FILTER
bool "filters "
default n
if USING_KNOWING_FILTER
menuconfig USING_MEAN_FILTER
bool "Using mean filter"
default n
if USING_MEAN_FILTER
source "$APP_DIR/Framework/knowing/filter/mean_filter/Kconfig"
endif
menuconfig USING_KALMAN_FILTER
bool "Using kalman filter"
default n
if USING_KALMAN_FILTER
source "$APP_DIR/Framework/knowing/filter/kalman_filter/Kconfig"
endif
menuconfig USING_LOW_PASS_FILTER
bool "Using low pass filter"
default n
if USING_LOW_PASS_FILTER
source "$APP_DIR/Framework/knowing/filter/low_pass_filter/Kconfig"
endif
menuconfig USING_HIGH_PASS_FILTER
bool "Using high pass filter"
default n
if USING_HIGH_PASS_FILTER
source "$APP_DIR/Framework/knowing/filter/high_pass_filter/Kconfig"
endif
endif

View File

@ -0,0 +1,14 @@
import os
Import('RTT_ROOT')
from building import *
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(path, 'SConscript'))
Return('objs')

View File

@ -0,0 +1,3 @@
config ONE_ORDER_RC_HIGH_PASS_FILTER
bool "one order rc hpf"
default n

View File

@ -0,0 +1,10 @@
from building import *
import os
cwd = GetCurrentDir()
src = []
if GetDepend(['ONE_ORDER_RC_HIGH_PASS_FILTER']):
src += ['one_order_rc_hpf.c']
group = DefineGroup('high_pass_filter', src, depend = ['USING_HIGH_PASS_FILTER'], CPPPATH = [cwd])
Return('group')

View File

@ -0,0 +1,22 @@
#include<one_order_rc_hpf.h>
void OneOrderRcHpfInit(OneOrderRcHpfHander* hander,float cutoff_fre,float sampling)
{
hander->vi = 0;
hander->fcutoff = cutoff_fre; // low pass filter cutoff frequency
hander->vo = 0;
hander->vo_prev = 0;
hander->fs = sampling; //sampling rate
hander->vi_prev = 0;
}
float OneOrderRcHpfFun(OneOrderRcHpfHander *hander)
{
float rc;
float alpha;
rc = (float) 1.0/2.0/3.1415926/hander->fcutoff;
alpha = rc/(rc+1/hander->fs);
hander->vo = (hander->vi - hander->vi_prev + hander->vo_prev)*alpha;
hander->vi_prev = hander ->vi;
hander->vo_prev = hander ->vo;
return hander->vo;
}

View File

@ -0,0 +1,17 @@
#ifndef _ONE_ORDER_RC_HPF_H
#define _ONE_ORDER_RC_HPF_H
typedef struct
{
float vi;
float vi_prev;
float vo_prev;
float vo;
float fcutoff;
float fs;
} OneOrderRcHpfHander;
void OneOrderRcHpfInit(OneOrderRcHpfHander* hander,float cutoff_fre,float sampling);
float OneOrderRcHpfFun(OneOrderRcHpfHander *hander);
#endif

View File

@ -0,0 +1,3 @@
config ONE_ORDER_KALMAN_FILTER
bool "one order kalman filter"
default n

View File

@ -0,0 +1,10 @@
from building import *
import os
cwd = GetCurrentDir()
src = []
if GetDepend(['ONE_ORDER_KALMAN_FILTER']):
src += ['one_order_kalman.c']
group = DefineGroup('kalman filter', src, depend = ['USING_KALMAN_FILTER'], CPPPATH = [cwd])
Return('group')

View File

@ -0,0 +1,29 @@
#include <one_order_kalman.h>
/**
* equation of state x = A*x + w; w~N(0,Q)
* Measurement equation y = C*x + v; v~N(0,R)
*
*/
void OneOrderKalmamInit(OneOrderKalmanHander *hander,float A,float C,float Q ,float R)
{
hander->A = A;
hander->A2 = A * A;
hander->C = C;
hander->C2 = C * C;
hander->Q = Q;
hander->R = R;
hander->x = 0;
hander->P = Q;
hander->K = 1;
}
float OneOrderKalmanFun(OneOrderKalmanHander *hander,float measure)
{
hander->x = hander->A * hander->x; //state prediction
hander->P = hander->A2 * hander->P + hander->Q; //covariance prediction
hander->K = hander->P * hander->C / (hander->C2 * hander->P + hander->R); //calculate kalman gain
hander->x = hander->x + hander->K * (measure- hander->C * hander->x); //state correct
hander->P = (1 - hander->K * hander->C) * hander->P; //covariance correction
return hander->C * hander->x; //return resault
}

View File

@ -0,0 +1,23 @@
#ifndef _ONE_ORDER_KALMAN_H_
#define _ONE_ORDER_KALMAN_H_
/**
* equation of state x = A*x + w; w~N(0,Q)
* Measurement equation y = C*x + v; v~N(0,R)
*
*/
typedef struct
{
float A;
float C;
float A2; //A*A
float C2; //C*C
float Q;
float R;
float K;
float P;
float x;
}OneOrderKalmanHander;
void OneOrderKalmamInit(OneOrderKalmanHander *hander,float A,float C,float Q ,float R);
float OneOrderKalmanFun(OneOrderKalmanHander *hander,float measure);
#endif

View File

@ -0,0 +1,3 @@
config ONE_ORDER_RC_LOW_PASS_FILTER
bool "one order rc lpf"
default n

View File

@ -0,0 +1,10 @@
from building import *
import os
cwd = GetCurrentDir()
src = []
if GetDepend(['ONE_ORDER_RC_LOW_PASS_FILTER']):
src += ['one_order_rc_lpf.c']
group = DefineGroup('low pass filter', src, depend = ['USING_LOW_PASS_FILTER'], CPPPATH = [cwd])
Return('group')

View File

@ -0,0 +1,22 @@
#include<one_order_rc_lpf.h>
void OneOrderRcLpfInit(OneOrderRcLpfHander* hander,float cutoff_fre,float sampling)
{
hander->vi = 0;
hander->fcutoff = cutoff_fre; // low pass filter cutoff frequency
hander->vo = 0;
hander->vo_prev = 0;
hander->fs = sampling; //sampling rate
}
float OneOrderRcLpfFun(OneOrderRcLpfHander *hander)
{
float rc;
float alpha1;
float alpha2;
rc = (float) 1.0/2.0/3.1415926/hander->fcutoff;
alpha1 = 1/(1+rc*hander->fs);
alpha2 = rc*hander->fs/(1+rc*hander->fs);
hander->vo = alpha1*hander->vi + alpha2 *hander->vo_prev;
hander->vo_prev = hander ->vo;
return hander->vo;
}

View File

@ -0,0 +1,16 @@
#ifndef _ONE_ORDER_RC_LPF_H
#define _ONE_ORDER_RC_LPF_H
typedef struct
{
float vi;
float vo_prev;
float vo;
float fcutoff;
float fs;
} OneOrderRcLpfHander;
void OneOrderRcLpfInit(OneOrderRcLpfHander* hander,float cutoff_fre,float sample);
float OneOrderRcLpfFun(OneOrderRcLpfHander *hander);
#endif

View File

@ -0,0 +1,8 @@
config SLIDING_WINDOW_MEAN_FILTER
bool "sliding window mean filter"
select LIB_USING_QUEUE
default n
config ORDINARY_MEAN_FILTER
bool "ordinary mean filter"
default n

View File

@ -0,0 +1,12 @@
from building import *
import os
cwd = GetCurrentDir()
src = []
if GetDepend(['SLIDING_WINDOW_MEAN_FILTER']):
src += ['sliding_window_mean_filter.c']
if GetDepend(['ORDINARY_MEAN_FILTER']):
src += ['ordinary_mean_filter.c']
group = DefineGroup('mean_filter', src, depend = ['USING_MEAN_FILTER'], CPPPATH = [cwd])
Return('group')

View File

@ -0,0 +1,16 @@
#include <ordinary_mean_filter.h>
/**
* @description:
* @param {int *} hander array address
* @param {int} len array length
* @return {*}
*/
int OrdinaryMeanFilter(int * hander,int len)
{
int sum = 0;
for(int i = 0;i < len ;i++)
{
sum = sum + *(hander +i);
}
return (int)(sum/len);
}

View File

@ -0,0 +1,4 @@
#ifndef _ORDINARY_MEAN_FILTER_H
#define _ORDINARY_MEAN_FILTER_H
int OrdinaryMeanFilter(int * hander,int len);
#endif

View File

@ -0,0 +1,26 @@
#include <sliding_window_mean_filter.h>
void SlidingWindowsMeanFliterInit(SlidingWindowsHander * hander,unsigned int window_len)
{
hander->window_len = window_len;
hander->sumlast = 0;
InitQueue(&(hander->window_queue));
}
int SlidingWindowsMeanFliterFun(SlidingWindowsHander * hander,int newvalue)
{
int headtemf = 0;
if(QueueLength(&(hander->window_queue)) < hander->window_len)
{
EnQueue(&(hander->window_queue),newvalue);
hander->sumlast = hander->sumlast + newvalue;
return (int)((hander->sumlast)/(QueueLength(&(hander->window_queue))));
}
else
{
DeQueue(&(hander->window_queue),&headtemf);
hander->sumlast = hander->sumlast - headtemf + newvalue;
EnQueue(&(hander->window_queue),newvalue);
return (int)((hander->sumlast)/(hander->window_len));
}
}

View File

@ -0,0 +1,15 @@
#ifndef _SLIDING_WINDOW_MEAN_FILTER_H
#define _SLIDING_WINDOW_MEAN_FILTER_H
#include <queue.h>
typedef struct
{
SqQueue window_queue;
unsigned int window_len; //the window_len value must less than MAXSIZE 1024
long long int sumlast;
}SlidingWindowsHander;
void SlidingWindowsMeanFliterInit(SlidingWindowsHander * hander,unsigned int window_len);
int SlidingWindowsMeanFliterFun(SlidingWindowsHander * hander,int newvalue);
#endif

View File

@ -1,5 +1,6 @@
menuconfig USING_KPU_POSTPROCESSING
bool "kpu model postprocessing"
default y
source "$APP_DIR/Framework/knowing/kpu-postprocessing/yolov2/Kconfig"
if USING_KPU_POSTPROCESSING
source "$APP_DIR/Framework/knowing/kpu-postprocessing/yolov2/Kconfig"
endif

View File

@ -0,0 +1,4 @@
menuconfig USING_OTA_MODEL
bool "OTA (KPU MODEL)"
select PKG_USING_RW007
default n

View File

@ -0,0 +1,10 @@
from building import *
import os
cwd = GetCurrentDir()
src = []
if GetDepend(['USING_OTA_MODEL']):
src += ['httpclient.c']
group = DefineGroup('ota model', src, depend = [], CPPPATH = [cwd])
Return('group')

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,132 @@
/*
* @Author: chunyexixiaoyu
* @Date: 2021-08-26 13:53:03
* @LastEditTime: 2021-08-30 14:44:05
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \xiuos\APP_Framework\Framework\knowing\ota\httpclient.h
*/
#ifndef _OTA_HTTPCLIENT_H
#define _OTA_HTTPCLIENT_H
#include <transform.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef HTTP_MALLOC
#define HTTP_MALLOC malloc
#endif
#ifndef HTTP_CALLOC
#define HTTP_CALLOC calloc
#endif
#ifndef HTTP_REALLOC
#define HTTP_REALLOC realloc
#endif
#ifndef HTTP_FREE
#define HTTP_FREE free
#endif
#ifndef HTTP_STRDUP
#define HTTP_STRDUP strdup
#endif
#define HTTPCLIENT_SW_VERSION "2.2.0"
#define HTTPCLIENT_SW_VERSION_NUM 0x20200
#define HTTPCLIENT_HEADER_BUFSZ 4096
#define HTTPCLIENT_RESPONSE_BUFSZ 4096
#define HTTPCLIENT_DEFAULT_TIMEO 6
enum webClientStatus
{
HTTPCLIENT_OK,
HTTPCLIENT_ERROR,
HTTPCLIENT_TIMEOUT,
HTTPCLIENT_NOMEM,
HTTPCLIENT_NOSOCKET,
HTTPCLIENT_NOBUFFER,
HTTPCLIENT_CONNECT_FAILED,
HTTPCLIENT_DISCONNECT,
HTTPCLIENT_FILE_ERROR,
};
enum httpClientMethod
{
WEBCLIENT_USER_METHOD,
WEBCLIENT_GET,
WEBCLIENT_POST,
};
struct httpClientHeader
{
char *buffer;
size_t length; /* content header buffer size */
size_t size; /* maximum support header size */
};
struct httpClientSession
{
struct httpClientHeader *header; /* webclient response header information */
int socket;
int resp_status;
char *host; /* server host */
char *req_url; /* HTTP request address*/
int chunk_sz;
int chunk_offset;
int content_length;
size_t content_remainder; /* remainder of content length */
int is_tls; /* HTTPS connect */
};
/* create webclient session and set header response size */
struct httpClientSession *httpClientSessionCreate(size_t header_sz);
/* send HTTP GET request */
int httpClientGet(struct httpClientSession *session, const char *URI);
int httpClientGetPosition(struct httpClientSession *session, const char *URI, int position);
/* send HTTP POST request */
int httpClientPost(struct httpClientSession *session, const char *URI, const void *post_data, size_t data_len);
/* close and release wenclient session */
int httpClientClose(struct httpClientSession *session);
int httpClientSetTimeout(struct httpClientSession *session, int millisecond);
/* send or receive data from server */
int httpClientRead(struct httpClientSession *session, void *buffer, size_t size);
int httpClientWrite(struct httpClientSession *session, const void *buffer, size_t size);
/* webclient GET/POST header buffer operate by the header fields */
int httpClientHeaderFieldsAdd(struct httpClientSession *session, const char *fmt, ...);
const char *httpClientHeaderFieldsGet(struct httpClientSession *session, const char *fields);
/* send HTTP POST/GET request, and get response data */
int httpClientResponse(struct httpClientSession *session, void **response, size_t *resp_len);
int httpClientRequest(const char *URI, const char *header, const void *post_data, size_t data_len, void **response, size_t *resp_len);
int httpClientRequestHeaderAdd(char **request_header, const char *fmt, ...);
int httpClientRespStatusGet(struct httpClientSession *session);
int httpClientContentLengthGet(struct httpClientSession *session);
/*
file system must be supported
*/
/* file related operations */
int httpClientGetFile(const char *URI, const char *filename);
int httpClientPostFile(const char *URI, const char *filename, const char *form_data);
extern long int strtol(const char *nptr, char **endptr, int base);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -22,7 +22,13 @@
#define TRANSFORM_H
#include <rtthread.h>
#include <rtdevice.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <errno.h>
#include <pthread.h>
#include <sched.h>
#include <unistd.h>
@ -33,10 +39,19 @@
#ifdef DRV_USING_OV2640
#include <drv_ov2640.h>
#endif
#if defined(RT_USING_SAL)
#include <netdb.h>
#include <sys/socket.h>
#else
#include <lwip/netdb.h>
#include <lwip/sockets.h>
#endif /* RT_USING_SAL */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif

View File

@ -11,4 +11,5 @@ menu "lib"
bool "app select other lib"
endchoice
source "$APP_DIR/lib/cJSON/Kconfig"
source "$APP_DIR/lib/queue/Kconfig"
endmenu

View File

@ -0,0 +1,3 @@
menuconfig LIB_USING_QUEUE
bool "USING QUEUE"
default n

View File

@ -0,0 +1,10 @@
from building import *
import os
cwd = GetCurrentDir()
src = Glob('*.c')
group = DefineGroup('queue', src, depend = ['LIB_USING_QUEUE'], CPPPATH = [cwd])
Return('group')

View File

@ -0,0 +1,104 @@
/*
* @Author: chunyexixiaoyu
* @Date: 2021-08-16 15:16:51
* @LastEditTime: 2021-08-18 14:45:47
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \xiuos\APP_Framework\lib\queue\queue.c
*/
#include <queue.h>
/**
* @description: Initialize an empty queue
* @param {SqQueue} *Q queue struct
* @return {*}
*/
Status InitQueue(SqQueue *Q)
{
Q->front=0;
Q->rear=0;
return OK;
}
/**
* @description: Clear Q to an empty queue
* @param {SqQueue} *Q queue struct
* @return {*}
*/
Status ClearQueue(SqQueue *Q)
{
Q->front=Q->rear=0;
return OK;
}
/**
* @description: Return TRUE if Q is an empty queue, FALSE otherwise
* @param {SqQueue} *Q queue struct
* @return TRUE
* FALSE
*/
Status QueueEmpty(SqQueue *Q)
{
if(Q->front==Q->rear)
return TRUE;
else
return FALSE;
}
/**
* @description: Returns the number of elements of Q, which is the current length of the queue
* @param {SqQueue} *Q queue struct
* @return length of the queue
*/
int QueueLength(SqQueue *Q)
{
return (Q->rear-Q->front+MAXSIZE)%MAXSIZE;
}
/**
* @description: If the queue is not empty, return the header element of Q with e and OK, otherwise return ERROR
* @param {SqQueue} *Q queue struct
* @param {QElemType} *e header element
* @return TRUE
* FALSE
*/
Status GetHead(SqQueue *Q,QElemType *e)
{
if(Q->front==Q->rear)
return ERROR;
*e=Q->data[Q->front];
return OK;
}
/**
* @description: If the queue is not full, insert element E as Q's new tail element
* @param {SqQueue} *Q queue struct
* @param {QElemType} e new element
* @return TRUE insert successfully
* FALSE
*/
Status EnQueue(SqQueue *Q,QElemType e)
{
if ((Q->rear+1)%MAXSIZE == Q->front)
return ERROR;
Q->data[Q->rear]=e;
Q->rear=(Q->rear+1)%MAXSIZE;
return OK;
}
/**
* @description: If the queue is not empty, the header element in Q is removed and its value is returned with e
* @param {SqQueue} *Q
* @param {QElemType} *e the header element
* @return {*}
*/
Status DeQueue(SqQueue *Q,QElemType *e)
{
if (Q->front == Q->rear)
return ERROR;
*e=Q->data[Q->front];
Q->front=(Q->front+1)%MAXSIZE;
return OK;
}

View File

@ -0,0 +1,34 @@
/*
* @Author: chunyexixiaoyu
* @Date: 2021-08-16 15:16:51
* @LastEditTime: 2021-08-18 14:48:11
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \xiuos\APP_Framework\lib\queue\queue.h
*/
#ifndef __QUEUE_H__
#define __QUEUE_H__
#include <stdio.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define MAXSIZE 1024
typedef int Status;
typedef int QElemType;
typedef struct
{
QElemType data[MAXSIZE];
int front;
int rear;
}SqQueue;
Status InitQueue(SqQueue *Q);
Status ClearQueue(SqQueue *Q);
Status QueueEmpty(SqQueue *Q);
Status GetHead(SqQueue *Q,QElemType *e);
Status EnQueue(SqQueue *Q,QElemType e);
Status DeQueue(SqQueue *Q,QElemType *e);
int QueueLength(SqQueue *Q);
#endif