Skip to content

Commit 3f0b3e4

Browse files
authored
Merge pull request #9 from ErickOF/jvillalobos/sobel-module
Integrating sobel module into dev
2 parents e4e57ad + cc77e0d commit 3f0b3e4

File tree

9 files changed

+520
-0
lines changed

9 files changed

+520
-0
lines changed

modules/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
ifndef USER_DEF_SYSTEMC_DIR
12
SYSTEMC?=$(HOME)/systemc-2.3.3
3+
endif # USER_DEF_SYSTEMC_DIR
24
TARGET?=test
35

46
# Compiler
@@ -17,6 +19,15 @@ BINDIR=./
1719
INCDIR=-I. -I./include -I$(SYSTEMC)/include -Ibasic_protocol -I$(SYSTEMC)/include/tlm_core/tlm_2
1820
LIBDIR=-L. -L$(SYSTEMC)/lib-linux64
1921

22+
ifdef INCLUDE_OPENCV
23+
# Target
24+
LIBS+=-lopencv_imgcodecs -lopencv_core -lopencv_highgui -lopencv_imgproc
25+
26+
# Source directories
27+
INCDIR+=-I/usr/local/include/opencv4
28+
LIBDIR+=-L/usr/local/lib
29+
endif # INCLUDE_OPENCV
30+
2031
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
2132
INCLUDES := $(wildcard $(INCDIR)/*.hpp)
2233
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)

modules/edge-detector/Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Adding stb lib for image handling
2+
INCDIR_STB=lib/stb
3+
INCLUDES_STB := $(wildcard $(INCDIR_STB)/*.h)
4+
5+
# Include common Makefile
6+
include ../Makefile
7+
8+
# Include stb lib for compilation
9+
INCLUDES += INCLUDES_STB
10+
11+
# Defining preprocessor directive for debug
12+
ifdef IPS_DEBUG_EN
13+
CFLAGS += -DIPS_DEBUG_EN
14+
LFLAGS += -DIPS_DEBUG_EN
15+
endif # IPS_DEBUG_EN
16+
17+
# Defining preprocessor directive for dumping enable
18+
ifdef IPS_DUMP_EN
19+
CFLAGS += -DIPS_DUMP_EN
20+
LFLAGS += -DIPS_DUMP_EN
21+
endif # IPS_DUMP_EN
22+
23+
# Defining preprocessor directive for normalizing the resulting magnitude
24+
ifdef TEST_NORMALIZE_MAGNITUDE
25+
CFLAGS += -DTEST_NORMALIZE_MAGNITUDE
26+
LFLAGS += -DTEST_NORMALIZE_MAGNITUDE
27+
endif # TEST_NORMALIZE_MAGNITUDE
28+
29+
# Defining preprocessor directive for using PV model
30+
ifdef EDGE_DETECTOR_PV_EN
31+
CFLAGS += -DEDGE_DETECTOR_PV_EN
32+
LFLAGS += -DEDGE_DETECTOR_PV_EN
33+
endif # EDGE_DETECTOR_PV_EN
34+
35+
# Defining preprocessor directive for using PV model
36+
ifdef EDGE_DETECTOR_LT_EN
37+
CFLAGS += -DEDGE_DETECTOR_LT_EN
38+
LFLAGS += -DEDGE_DETECTOR_LT_EN
39+
endif # EDGE_DETECTOR_LT_EN
40+
41+
# Defining preprocessor directive for using PV model
42+
ifdef EDGE_DETECTOR_AT_EN
43+
CFLAGS += -DEDGE_DETECTOR_AT_EN
44+
LFLAGS += -DEDGE_DETECTOR_AT_EN
45+
endif # EDGE_DETECTOR_AT_EN
46+
47+
# Run the compiled file
48+
run:
49+
@./test
50+
51+
# Show waveform
52+
waveform:
53+
@gtkwave edge_detector.vcd

modules/edge-detector/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# **Edge Detector Module**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifdef EDGE_DETECTOR_LT_EN
2+
#ifndef SOBEL_EDGE_DETECTOR_HPP
3+
#define SOBEL_EDGE_DETECTOR_HPP
4+
5+
#include <systemc.h>
6+
7+
SC_MODULE(Edge_Detector)
8+
{
9+
10+
int localWindow[3][3];
11+
12+
const int sobelGradientX[3][3] = {{-1, 0, 1},
13+
{-2, 0, 2},
14+
{-1, 0, 1}};
15+
const int sobelGradientY[3][3] = {{-1, -2, -1},
16+
{ 0, 0, 0},
17+
{ 1, 2, 1}};
18+
19+
int resultSobelGradientX;
20+
int resultSobelGradientY;
21+
22+
sc_event gotLocalWindow, finishedSobelGradientX, finishedSobelGradientY;
23+
24+
SC_CTOR(Edge_Detector)
25+
{
26+
SC_THREAD(compute_sobel_gradient_x);
27+
SC_THREAD(compute_sobel_gradient_y);
28+
}
29+
30+
void set_local_window(int window[3][3]);
31+
32+
void compute_sobel_gradient_x();
33+
34+
void compute_sobel_gradient_y();
35+
36+
int obtain_sobel_gradient_x();
37+
38+
int obtain_sobel_gradient_y();
39+
40+
};
41+
42+
#endif // SOBEL_EDGE_DETECTOR_HPP
43+
#endif // EDGE_DETECTOR_LT_EN
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifdef EDGE_DETECTOR_PV_EN
2+
#ifndef SOBEL_EDGE_DETECTOR_HPP
3+
#define SOBEL_EDGE_DETECTOR_HPP
4+
5+
#include <systemc.h>
6+
7+
SC_MODULE(Edge_Detector)
8+
{
9+
10+
int localWindow[3][3];
11+
12+
const int sobelGradientX[3][3] = {{-1, 0, 1},
13+
{-2, 0, 2},
14+
{-1, 0, 1}};
15+
const int sobelGradientY[3][3] = {{-1, -2, -1},
16+
{ 0, 0, 0},
17+
{ 1, 2, 1}};
18+
19+
int resultSobelGradientX;
20+
int resultSobelGradientY;
21+
22+
SC_CTOR(Edge_Detector)
23+
{
24+
// SC_METHOD(hello_world);
25+
}
26+
27+
void set_local_window(int window[3][3]);
28+
29+
void compute_sobel_gradient_x();
30+
31+
void compute_sobel_gradient_y();
32+
33+
int obtain_sobel_gradient_x();
34+
35+
int obtain_sobel_gradient_y();
36+
37+
};
38+
39+
#endif // SOBEL_EDGE_DETECTOR_HPP
40+
#endif // EDGE_DETECTOR_PV_EN
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#ifdef EDGE_DETECTOR_LT_EN
2+
#ifndef SOBEL_EDGE_DETECTOR_CPP
3+
#define SOBEL_EDGE_DETECTOR_CPP
4+
5+
#include "sobel_edge_detector_lt_model.hpp"
6+
7+
void Edge_Detector::set_local_window(int window[3][3])
8+
{
9+
for (int i = 0; i < 3; i++)
10+
{
11+
for (int j = 0; j < 3; j++)
12+
{
13+
this->localWindow[i][j] = window[i][j];
14+
}
15+
}
16+
gotLocalWindow.notify(10, SC_NS);
17+
}
18+
19+
void Edge_Detector::compute_sobel_gradient_x()
20+
{
21+
while (true)
22+
{
23+
wait(gotLocalWindow);
24+
this->resultSobelGradientX = 0;
25+
26+
for (int i = 0; i < 3; i++)
27+
{
28+
for (int j = 0; j < 3; j++)
29+
{
30+
this->resultSobelGradientX += this->localWindow[i][j] * this->sobelGradientX[i][j];
31+
}
32+
}
33+
finishedSobelGradientX.notify(5, SC_NS);
34+
}
35+
}
36+
37+
void Edge_Detector::compute_sobel_gradient_y()
38+
{
39+
while (true)
40+
{
41+
wait(gotLocalWindow);
42+
this->resultSobelGradientY = 0;
43+
44+
for (int i = 0; i < 3; i++)
45+
{
46+
for (int j = 0; j < 3; j++)
47+
{
48+
this->resultSobelGradientY += this->localWindow[i][j] * this->sobelGradientY[i][j];
49+
}
50+
}
51+
finishedSobelGradientY.notify(5, SC_NS);
52+
}
53+
}
54+
55+
int Edge_Detector::obtain_sobel_gradient_x()
56+
{
57+
return this->resultSobelGradientX;
58+
}
59+
60+
int Edge_Detector::obtain_sobel_gradient_y()
61+
{
62+
return this->resultSobelGradientY;
63+
}
64+
65+
#endif // SOBEL_EDGE_DETECTOR_CPP
66+
#endif // EDGE_DETECTOR_LT_EN
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifdef EDGE_DETECTOR_PV_EN
2+
#ifndef SOBEL_EDGE_DETECTOR_CPP
3+
#define SOBEL_EDGE_DETECTOR_CPP
4+
5+
#include "sobel_edge_detector_pv_model.hpp"
6+
7+
void Edge_Detector::set_local_window(int window[3][3])
8+
{
9+
for (int i = 0; i < 3; i++)
10+
{
11+
for (int j = 0; j < 3; j++)
12+
{
13+
this->localWindow[i][j] = window[i][j];
14+
}
15+
}
16+
}
17+
18+
void Edge_Detector::compute_sobel_gradient_x()
19+
{
20+
this->resultSobelGradientX = 0;
21+
22+
for (int i = 0; i < 3; i++)
23+
{
24+
for (int j = 0; j < 3; j++)
25+
{
26+
this->resultSobelGradientX += this->localWindow[i][j] * this->sobelGradientX[i][j];
27+
}
28+
}
29+
}
30+
31+
void Edge_Detector::compute_sobel_gradient_y()
32+
{
33+
this->resultSobelGradientY = 0;
34+
35+
for (int i = 0; i < 3; i++)
36+
{
37+
for (int j = 0; j < 3; j++)
38+
{
39+
this->resultSobelGradientY += this->localWindow[i][j] * this->sobelGradientY[i][j];
40+
}
41+
}
42+
}
43+
44+
int Edge_Detector::obtain_sobel_gradient_x()
45+
{
46+
this->compute_sobel_gradient_x();
47+
48+
return this->resultSobelGradientX;
49+
}
50+
51+
int Edge_Detector::obtain_sobel_gradient_y()
52+
{
53+
this->compute_sobel_gradient_y();
54+
55+
return this->resultSobelGradientY;
56+
}
57+
58+
#endif // SOBEL_EDGE_DETECTOR_CPP
59+
#endif // EDGE_DETECTOR_PV_EN

0 commit comments

Comments
 (0)