Skip to content

Commit

Permalink
Merge PR #204: felipe-m/iss199-sobel
Browse files Browse the repository at this point in the history
5th tutorial verilator + imgui + camera sobel
  • Loading branch information
felipe-m authored Oct 8, 2023
2 parents bf17d62 + e9e3c35 commit 011625f
Show file tree
Hide file tree
Showing 9 changed files with 925 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sim_fpga/tutorial/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ More info in its [tutorial 3 readme](./tut03)

In this example, the video frame size has increased considerably, from 160x120 to 640x480. To test the performance with this size

More info in its [tutorial 4 readme](./tut04)
More info in its [tutorial 4 readme](./tut04)


## [Tutorial 5](./tut05)

Instead of a color filter, this example includes a more complex filter such as Sobel, to check the performance in simulation.

More info in its [tutorial 5 readme](./tut05)

The filter has been take from [../../phys_fpga/alhambra_ii/apio/ov7670_yuv_80x60_sobel/edge_proc.v](../../phys_fpga/alhambra_ii/apio/ov7670_yuv_80x60_sobel/edge_proc.v)

64 changes: 64 additions & 0 deletions sim_fpga/tutorial/tut05/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
SIM_DIR := $(realpath $(dir $(MKFILE_PATH))/../..)
PROJECT_DIR := $(realpath $(SIM_DIR)/..)
IMGUI_DIR = $(PROJECT_DIR)/third_party/imgui
EXAMPLE_DIR = $(SIM_DIR)/tutorial/tut05
RTL_DIR = $(EXAMPLE_DIR)/rtl
INC_DIR = $(EXAMPLE_DIR)/include
SRC_DIR = $(EXAMPLE_DIR)/src
ASSETS_DIR := $(SRC_DIR)
SOURCES = $(SRC_DIR)/main.cpp
SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
V_SOURCES = $(RTL_DIR)/edge_proc.v
UNAME_S := $(shell uname -s)
LINUX_GL_LIBS = -lGL

CXXFLAGS = -I$(INC_DIR) -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -DASSETS_DIR=\\\"$(ASSETS_DIR)\\\" -g
LIBS =

##---------------------------------------------------------------------
## BUILD FLAGS PER PLATFORM
##---------------------------------------------------------------------

ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
LIBS += $(LINUX_GL_LIBS) -ldl `sdl2-config --libs` `pkg-config --libs opencv4`

CXXFLAGS += `sdl2-config --cflags` `pkg-config --cflags opencv4`
CFLAGS = $(CXXFLAGS)
endif

ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "Mac OS X"
LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs`
LIBS += -L/usr/local/lib -L/opt/local/lib

CXXFLAGS += `sdl2-config --cflags`
CXXFLAGS += -I/usr/local/include -I/opt/local/include
CFLAGS = $(CXXFLAGS)
endif

ifeq ($(OS), Windows_NT)
ECHO_MESSAGE = "MinGW"
LIBS += -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2`

CXXFLAGS += `pkg-config --cflags sdl2`
CFLAGS = $(CXXFLAGS)
endif

##---------------------------------------------------------------------
## BUILD RULES
##---------------------------------------------------------------------

all: obj_dir/Vedge_proc
@echo Build complete for $(ECHO_MESSAGE)

obj_dir/Vedge_proc.h: $(V_SOURCES)
verilator --cc $(V_SOURCES) -x-assign unique --trace -CFLAGS "$(CXXFLAGS)" --exe $(SOURCES) -I$(RTL_DIR)

obj_dir/Vedge_proc: obj_dir/Vedge_proc.h $(SOURCES)
make -j 4 -C obj_dir/ -f Vedge_proc.mk Vedge_proc LIBS="$(LIBS)"

clean:
rm -rf obj_dir
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions sim_fpga/tutorial/tut05/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Verilator+GUI Tutorial 5

Edge processing using Sobel filter.

The edge processing has been modified from:

* [../../../phys_fpga/alhambra_ii/apio/ov7670_yuv_80x60_sobel/edge_proc.v](../../../phys_fpga/alhambra_ii/apio/ov7670_yuv_80x60_sobel/edge_proc.v)

---

![Screenshot Sobel Horizontal 160x120](imgs/sobel_horizontal_160x120.jpg)

---

![Screenshot Sobel Vertical 160x120](imgs/sobel_vertical_160x120.jpg)

---

## Change image size

To change the image size, you just have to change both src/main.cpp and rtl/edge_proc.v

In src/main.cpp change the following lines to the desired values, here for example to 640x480

const int IMG_COLS = 640;
const int IMG_ROWS = 480;


In rtl/edge_proc.v change the following lines to the same desired values

c_img_cols = 640, // 10 bits
c_img_rows = 480, // 9 bits

The achieved fps are much lower (less than 1fps):

![Screenshot Sobel Horizontal 640x480](imgs/sobel_horizontal_640x480.jpg)
Loading

0 comments on commit 011625f

Please sign in to comment.