Compare commits

..

No commits in common. 'd477d24d39c538bef36762d22ed2bd1978071370' and '1b875f6d70461afe0526ee90ba19211bd856b254' have entirely different histories.

@ -1,36 +1,17 @@
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.
NCC = clang
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
NATIVE_CC=clang #sod: sod.c
NATIVE_CFLAGS = -I. -DCPU_FREQ=3600 -O3 -lm -DSOD_DISABLE_CNN -DLIBCOX_DISABLE_DISK_IO # $(CC) sod.c samples/cnn_face_detection.c -o sod_face_detect -I. $(CFLAGS)
OPTFLAGS=-O3 -flto EXT = out
WEXT = wout
WASM_CC=wasm32-unknown-unknown-wasm-clang
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
MEMC_64=64bit_nix.c
# for aWsm compiler
# Currently only uses wasmception backing
AWSM_DIR=${BASE_DIR}/awsm/
AWSM_RT_DIR=${AWSM_DIR}/runtime/
AWSM_RT_MEM=${AWSM_RT_DIR}/memory/
AWSM_RT_LIBC=${AWSM_RT_DIR}/libc/wasmception_backing.c
AWSM_RT_ENV=${AWSM_RT_DIR}/libc/env.c
AWSM_RT_RT=${AWSM_RT_DIR}/runtime.c
AWSM_RT_MEMC=${AWSM_RT_MEM}/${MEMC_64}
DUMMY=${AWSM_DIR}/code_benches/dummy.c
# for SLEdge serverless runtime
SLEDGE_RT_DIR=${BASE_DIR}/runtime/
SLEDGE_RT_INC=${SLEDGE_RT_DIR}/include/
SLEDGE_MEMC=${SLEDGE_RT_DIR}/compiletime/memory/${MEMC_64}
SLEDGE_BIN_DIR=${SLEDGE_RT_DIR}/bin/
WASMISA=${SLEDGE_RT_DIR}/compiletime/instr.c
SAMPLES = resize_image \ SAMPLES = resize_image \
license_plate_detection license_plate_detection
@ -59,39 +40,34 @@ SAMPLES = resize_image \
# rotate_image \ # rotate_image \
# sobel_operator_img # sobel_operator_img
all: dir copy SAMPLESOUT = $(SAMPLES:%=%.$(EXT))
SAMPLESWOUT = $(SAMPLES:%=%.$(WEXT))
all: clean dir copy
native: samples
wasm: samples.wasm
# samples.wasm
# samples
dir: dir:
@mkdir -p bin/ mkdir -p bin/
copy: copy:
cp samples/*.png bin/ cp samples/*.png bin/
cp samples/*.jpg bin/ cp samples/*.jpg bin/
.PHONY: samples.wasm samples: $(SAMPLESOUT)
samples.wasm: resize_image.wasm license_plate_detection.wasm
.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 samples.wasm: $(SAMPLESWOUT)
@$(WASM_CC) $(WASM_CFLAGS) $(OPTFLAGS) sod.c $< $(DUMMY) -o bin/$@
%.out: %.wasm %.$(EXT):
@$(AWSM_CC) $< -o $(<:.wasm=.bc) $(NCC) $(NCFLAGS) sod.c samples/$(@:%.$(EXT)=%.c) -o bin/$@
@$(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 %.$(WEXT):
@$(AWSM_CC) --inline-constant-globals --runtime-globals bin/$< -o bin/$(@:.so=.bc) $(WASMCC) $(WCFLAGS) $(WASMCFLAGS) $(OPTFLAGS) sod.c samples/$(@:%.$(WEXT)=%.c) $(DUMMY) -o bin/$(@:%.$(WEXT)=%.wasm)
@$(NATIVE_CC) --shared -fPIC ${CFLAGS} ${EXTRA_CFLAGS} $(OPTFLAGS) -DUSE_MEM_VM -I${SLEDGE_RT_INC} bin/$(@:.so=.bc) $(WASMISA) ${SLEDGE_MEMC} -o bin/$@ $(SFCC) bin/$(@:%.$(WEXT)=%.wasm) -o bin/$(@:%.$(WEXT)=%.bc)
$(CC) ${CFLAGS} ${EXTRA_CFLAGS} $(OPTFLAGS) -D$(USE_MEM) bin/$(@:%.$(WEXT)=%.bc) $(RT_LIBC) $(RT_RT) ${MEMC} -o bin/$@
.PHONY: clean
clean: clean:
rm -f bin/* rm -f bin/*
rm -f *.wasm
rm -f *.bc
rm -f *.so
rm -f *.out

@ -0,0 +1,38 @@
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/

@ -1 +0,0 @@
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, 13); sod_img dilImg = sod_dilate_image(cannyImg, 12);
/* 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,21 +122,12 @@ 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++) {
if (nbox > 0) { sod_image_draw_bbox_width(imgCopy, box[i], 5, 255., 0, 225.); // rose box
// 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);
@ -145,7 +136,6 @@ 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;
} }

@ -1,47 +0,0 @@
#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