Compare commits

...

10 Commits

@ -1,73 +1,97 @@
BASE_DIR=../ BASE_DIR=../../../
include Makefile.wasm.inc
AWSM_CC=awsm
# SOD does not generally require a Makefile to build. Just drop sod.c and its accompanying
# header files on your source tree and you are done. NATIVE_CC=clang
NCC = clang NATIVE_CFLAGS = -I. -DCPU_FREQ=3600 -O3 -lm -DSOD_DISABLE_CNN -DLIBCOX_DISABLE_DISK_IO
NCFLAGS = -I. -DCPU_FREQ=3600 -O3 -lm -DSOD_DISABLE_CNN -DLIBCOX_DISABLE_DISK_IO
WCFLAGS = -DWASM -I. -DSOD_DISABLE_CNN -lm -DLIBCOX_DISABLE_DISK_IO OPTFLAGS=-O3 -flto
#sod: sod.c WASM_CC=wasm32-unknown-unknown-wasm-clang
# $(CC) sod.c samples/cnn_face_detection.c -o sod_face_detect -I. $(CFLAGS) WASM_LDFLAGS=-Wl,-z,stack-size=524288,--allow-undefined,--no-threads,--stack-first,--no-entry,--export-all,--export=main,--export=dummy
WASM_CFLAGS=${WASM_LDFLAGS} -nostartfiles -DWASM -I. -DSOD_DISABLE_CNN -lm -DLIBCOX_DISABLE_DISK_IO
EXT = out
WEXT = wout MEMC_64=64bit_nix.c
SAMPLES = resize_image \ # for aWsm compiler
license_plate_detection # Currently only uses wasmception backing
AWSM_DIR=${BASE_DIR}/awsm/
#SAMPLES = batch_img_loading \ AWSM_RT_DIR=${AWSM_DIR}/runtime/
# blob_detection \ AWSM_RT_MEM=${AWSM_RT_DIR}/memory/
# canny_edge_detection \ AWSM_RT_LIBC=${AWSM_RT_DIR}/libc/wasmception_backing.c
# cnn_coco \ AWSM_RT_ENV=${AWSM_RT_DIR}/libc/env.c
# cnn_face_detection \ AWSM_RT_RT=${AWSM_RT_DIR}/runtime.c
# cnn_object_detection \ AWSM_RT_MEMC=${AWSM_RT_MEM}/${MEMC_64}
# cnn_voc \ DUMMY=${AWSM_DIR}/code_benches/dummy.c
# crop_image \
# dilate_image \ # for SLEdge serverless runtime
# erode_image \ SLEDGE_RT_DIR=${BASE_DIR}/runtime/
# grayscale_image \ SLEDGE_RT_INC=${SLEDGE_RT_DIR}/include/
# hilditch_thin \ SLEDGE_MEMC=${SLEDGE_RT_DIR}/compiletime/memory/${MEMC_64}
# hough_lines_detection \
# license_plate_detection \ SLEDGE_BIN_DIR=${SLEDGE_RT_DIR}/bin/
# minutiae \ WASMISA=${SLEDGE_RT_DIR}/compiletime/instr.c
# otsu_image \
# realnet_face_detection \ SAMPLES = resize_image \
# realnet_face_detection_embedded \ license_plate_detection
# realnet_train_model \
# resize_image \ #SAMPLES = batch_img_loading \
# rnn_text_gen \ # blob_detection \
# rotate_image \ # canny_edge_detection \
# sobel_operator_img # cnn_coco \
# cnn_face_detection \
SAMPLESOUT = $(SAMPLES:%=%.$(EXT)) # cnn_object_detection \
SAMPLESWOUT = $(SAMPLES:%=%.$(WEXT)) # cnn_voc \
# crop_image \
all: clean dir copy # dilate_image \
# erode_image \
native: samples # grayscale_image \
wasm: samples.wasm # hilditch_thin \
# samples.wasm # hough_lines_detection \
# samples # license_plate_detection \
# minutiae \
dir: # otsu_image \
mkdir -p bin/ # realnet_face_detection \
# realnet_face_detection_embedded \
copy: # realnet_train_model \
cp samples/*.png bin/ # resize_image \
cp samples/*.jpg bin/ # rnn_text_gen \
# rotate_image \
samples: $(SAMPLESOUT) # sobel_operator_img
samples.wasm: $(SAMPLESWOUT) all: dir copy
%.$(EXT): dir:
$(NCC) $(NCFLAGS) sod.c samples/$(@:%.$(EXT)=%.c) -o bin/$@ @mkdir -p bin/
%.$(WEXT): copy:
$(WASMCC) $(WCFLAGS) $(WASMCFLAGS) $(OPTFLAGS) sod.c samples/$(@:%.$(WEXT)=%.c) $(DUMMY) -o bin/$(@:%.$(WEXT)=%.wasm) cp samples/*.png bin/
$(SFCC) bin/$(@:%.$(WEXT)=%.wasm) -o bin/$(@:%.$(WEXT)=%.bc) cp samples/*.jpg bin/
$(CC) ${CFLAGS} ${EXTRA_CFLAGS} $(OPTFLAGS) -D$(USE_MEM) bin/$(@:%.$(WEXT)=%.bc) $(RT_LIBC) $(RT_RT) ${MEMC} -o bin/$@
.PHONY: samples.wasm
clean: samples.wasm: resize_image.wasm license_plate_detection.wasm
rm -f bin/*
.PHONY: samples.so
samples.so: resize_image.so license_plate_detection.so
.PHONY: samples.out
samples.out: resize_image.out license_plate_detection.out
%.wasm: samples/%.c
@$(WASM_CC) $(WASM_CFLAGS) $(OPTFLAGS) sod.c $< $(DUMMY) -o bin/$@
%.out: %.wasm
@$(AWSM_CC) $< -o $(<:.wasm=.bc)
@$(NATIVE_CC) ${CFLAGS} ${EXTRA_CFLAGS} $(OPTFLAGS) -DUSE_MEM_VM bin/$(<:.wasm=.bc) $(AWSM_RT_LIBC) $(AWSM_RT_RT) $(AWSM_RT_ENV) $(AWSM_RT_MEMC) -o $@
%.so: %.wasm
@$(AWSM_CC) --inline-constant-globals --runtime-globals bin/$< -o bin/$(@:.so=.bc)
@$(NATIVE_CC) --shared -fPIC ${CFLAGS} ${EXTRA_CFLAGS} $(OPTFLAGS) -DUSE_MEM_VM -I${SLEDGE_RT_INC} bin/$(@:.so=.bc) $(WASMISA) ${SLEDGE_MEMC} -o bin/$@
.PHONY: clean
clean:
rm -f bin/*
rm -f *.wasm
rm -f *.bc
rm -f *.so
rm -f *.out

@ -1,38 +0,0 @@
BASE=awsm
SFCC=silverfish
CC=clang
WASMCC=wasm32-unknown-unknown-wasm-clang
OPTFLAGS=-O3 -flto
# same stack-size for all
WASMLINKFLAGS=-Wl,-z,stack-size=524288,--allow-undefined,--no-threads,--stack-first,--no-entry,--export-all,--export=main,--export=dummy
WASMCFLAGS=${WASMLINKFLAGS} -nostartfiles
MEMC_64=64bit_nix.c
MEMC_NO=no_protection.c
MEMC_GEN=generic.c
MEMC_MPX=mpx.c
MEMC_SEG=segmented.c
# for silverfish
RT_DIR=${BASE_DIR}/runtime/
RT_MEM=${RT_DIR}/memory/
RT_LIBC=${RT_DIR}/libc/libc_backing.c
RT_RT=${RT_DIR}/runtime.c
MEMC=${RT_MEM}/${MEMC_64}
DUMMY=${BASE_DIR}/code_benches/dummy.c
# for awsm
ABASE_DIR=${BASE_DIR}/../
ART_DIR=${ABASE_DIR}/runtime/
ART_INC=${ART_DIR}/include/
USE_MEM=USE_MEM_VM
ifeq ($(USE_MEM),USE_MEM_VM)
AMEMC=${ART_DIR}/compiletime/memory/${MEMC_64}
endif
WASMISA=${ART_DIR}/compiletime/instr.c
ABIN_DIR=${ART_DIR}/bin/
TMP_DIR=tmp/

@ -0,0 +1 @@
gcc samples/resize_image.c sod.c -I./ -lm -o resver

@ -112,7 +112,7 @@ int main(int argc, char *argv[])
* Dilate the image say 12 times but you should experiment * Dilate the image say 12 times but you should experiment
* with different values for best results which depend * with different values for best results which depend
* on the quality of the input image/frame. */ * on the quality of the input image/frame. */
sod_img dilImg = sod_dilate_image(cannyImg, 12); sod_img dilImg = sod_dilate_image(cannyImg, 13);
/* Perform connected component labeling or blob detection /* Perform connected component labeling or blob detection
* now on the binary, canny edged, Gaussian noise reduced and * now on the binary, canny edged, Gaussian noise reduced and
* finally dilated image using our filter callback that should * finally dilated image using our filter callback that should
@ -122,12 +122,21 @@ int main(int argc, char *argv[])
int i, nbox; int i, nbox;
sod_image_find_blobs(dilImg, &box, &nbox, filter_cb); sod_image_find_blobs(dilImg, &box, &nbox, filter_cb);
/* Draw a box on each potential plate coordinates */ /* Draw a box on each potential plate coordinates */
for (i = 0; i < nbox; i++) {
sod_image_draw_bbox_width(imgCopy, box[i], 5, 255., 0, 225.); // rose box if (nbox > 0) {
// printf("x, y, w, h\n");
for (i = 0; i < nbox; i++) {
// print boxes to stdout
printf("%d, %d, %d, %d\n", box[i].x, box[i].y, box[i].w, box[i].h);
}
} else {
printf("0 boxes\n");
} }
sod_image_blob_boxes_release(box); sod_image_blob_boxes_release(box);
/* Finally save the output image to the specified path */ /* Finally save the output image to the specified path */
sod_img_save_as_jpeg(imgCopy, NULL, 0); // sod_img_save_as_jpeg(imgCopy, NULL, 0);
/* Cleanup */ /* Cleanup */
sod_free_image(imgIn); sod_free_image(imgIn);
sod_free_image(cannyImg); sod_free_image(cannyImg);
@ -136,6 +145,7 @@ int main(int argc, char *argv[])
sod_free_image(imgCopy); sod_free_image(imgCopy);
free(zInpbuf); free(zInpbuf);
e = get_time(); e = get_time();
print_time(s, e); // print_time(s, e);
fflush(stdout);
return 0; return 0;
} }

@ -0,0 +1,47 @@
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include "sod.h"
#define MAX_IMG_SZ 1024*1024
int main()
{
unsigned char *zInpbuf = NULL;
zInpbuf = malloc(MAX_IMG_SZ);
if (!zInpbuf)
{
perror("malloc");
return -1;
}
ssize_t imgSz = read(0, zInpbuf, MAX_IMG_SZ);
if (imgSz <= 0)
{
perror("read");
free(zInpbuf);
return -1;
}
sod_img imgIn = sod_img_load_from_mem(zInpbuf, imgSz, SOD_IMG_COLOR /* full color channels */);
if (imgIn.data == 0) {
/* Invalid path, unsupported format, memory failure, etc. */
//puts("Cannot load input image..exiting");
printf("Error loading input\n");
free(zInpbuf);
return -1;
}
for (int i = 0; i < imgIn.w * imgIn.h * imgIn.c; i++)
{
imgIn.data[i] = 255.0f - imgIn.data[i];
}
sod_img_save_as_png(imgIn, NULL);
sod_free_image(imgIn);
free(zInpbuf);
return 0;
}
Loading…
Cancel
Save