Skip to content

Commit 92bff78

Browse files
committed
Add rgb2gray module and tb of pv model
1 parent cc77e0d commit 92bff78

File tree

6 files changed

+179
-3
lines changed

6 files changed

+179
-3
lines changed

modules/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ TARGET?=test
55

66
# Compiler
77
CC=g++
8-
CFLAGS=-Wall -I. -O3 -g -Wextra -Wunused-function
8+
CFLAGS=-Wall -I. -O3 -g -std=c++17 -Wextra -Wunused-function
99

1010
# Target
1111
LD=g++
@@ -24,8 +24,8 @@ ifdef INCLUDE_OPENCV
2424
LIBS+=-lopencv_imgcodecs -lopencv_core -lopencv_highgui -lopencv_imgproc
2525

2626
# Source directories
27-
INCDIR+=-I/usr/local/include/opencv4
28-
LIBDIR+=-L/usr/local/lib
27+
INCDIR+=-I$(OPENCV_H_DIR)
28+
LIBDIR+=-L$(OPENCV_SO_DIR)
2929
endif # INCLUDE_OPENCV
3030

3131
SOURCES := $(wildcard $(SRCDIR)/*.cpp)

modules/rgb2gray/Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 RGB2GRAY_PV_EN
31+
CFLAGS += -DRGB2GRAY_PV_EN
32+
LFLAGS += -DRGB2GRAY_PV_EN
33+
endif # RGB2GRAY_PV_EN
34+
35+
# Run the compiled file
36+
run:
37+
@./test
38+
39+
# Show waveform
40+
waveform:
41+
@gtkwave rgb2gray.vcd
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifdef RGB2GRAY_PV_EN
2+
#ifndef RGB2GRAY_HPP
3+
#define RGB2GRAY_HPP
4+
5+
#include <systemc.h>
6+
7+
SC_MODULE(Rgb2Gray)
8+
{
9+
10+
unsigned char r;
11+
unsigned char g;
12+
unsigned char b;
13+
unsigned char gray_value;
14+
15+
SC_CTOR(Rgb2Gray)
16+
{
17+
}
18+
19+
void set_rgb_pixel(unsigned char r_val, unsigned char g_val, unsigned char b_val);
20+
21+
void compute_gray_value();
22+
23+
char obtain_gray_value();
24+
25+
};
26+
27+
#endif // RGB2GRAY_HPP
28+
#endif // RGB2GRAY_PV_EN
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifdef RGB2GRAY_PV_EN
2+
#ifndef RGB2GRAY_CPP
3+
#define RGB2GRAY_CPP
4+
5+
#include "rgb2gray_pv_model.hpp"
6+
7+
void Rgb2Gray::set_rgb_pixel(unsigned char r_val, unsigned char g_val, unsigned char b_val)
8+
{
9+
this->r = r_val;
10+
this->g = g_val;
11+
this->b = b_val;
12+
}
13+
14+
void Rgb2Gray::compute_gray_value()
15+
{
16+
this->gray_value = 0.299 * this->r + 0.587 * this->g + 0.114 * this->b;
17+
}
18+
19+
char Rgb2Gray::obtain_gray_value()
20+
{
21+
compute_gray_value();
22+
23+
return this->gray_value;
24+
}
25+
26+
#endif // RGB2GRAY_CPP
27+
#endif // RGB2GRAY_PV_EN
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#define int64 systemc_int64
2+
#define uint64 systemc_uint64
3+
#include <systemc.h>
4+
#undef int64
5+
#undef uint64
6+
#define int64 opencv_int64
7+
#define uint64 opencv_uint64
8+
#include <opencv2/opencv.hpp>
9+
#undef int64
10+
#undef uint64
11+
12+
#include "rgb2gray_pv_model.hpp"
13+
14+
using namespace cv;
15+
16+
int sc_main(int, char*[])
17+
{
18+
Mat colorImage;
19+
20+
unsigned char localR, localG, localB;
21+
unsigned char localResult;
22+
23+
// Pass command linke arguments
24+
sc_argc();
25+
sc_argv();
26+
27+
// Open VCD file
28+
sc_trace_file* wf = sc_create_vcd_trace_file("rgb2gray");
29+
wf->set_time_unit(1, SC_NS);
30+
31+
Rgb2Gray rgb2gray("rgb2gray");
32+
33+
colorImage = imread("../../tools/datagen/src/imgs/car.jpg", IMREAD_UNCHANGED);
34+
35+
if (colorImage.empty())
36+
{
37+
cout << "Image File " << "Not Found" << endl;
38+
39+
// wait for any key press
40+
return -1;
41+
}
42+
43+
Mat greyImage(colorImage.rows, colorImage.cols, CV_8UC1);
44+
45+
sc_start();
46+
47+
for (int i = 0; i < colorImage.rows; i++)
48+
{
49+
for (int j = 0; j < colorImage.cols; j++)
50+
{
51+
localR = colorImage.at<cv::Vec3b>(i, j)[2];
52+
localG = colorImage.at<cv::Vec3b>(i, j)[1];
53+
localB = colorImage.at<cv::Vec3b>(i, j)[0];
54+
rgb2gray.set_rgb_pixel(localR, localG, localB);
55+
localResult = rgb2gray.obtain_gray_value();
56+
57+
greyImage.at<uchar>(i, j) = localResult;
58+
}
59+
}
60+
61+
imshow("Window Name", colorImage);
62+
63+
waitKey(0);
64+
65+
imshow("Window Name", greyImage);
66+
67+
waitKey(0);
68+
69+
std::cout << "@" << sc_time_stamp() << " Terminating simulation" << std::endl;
70+
sc_close_vcd_trace_file(wf);
71+
72+
return 0;
73+
}

modules/rgb2gray/utils.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
export SYSTEMC=/usr/local/systemc-3.0.0
3+
export OPENCV_SO_DIR=/lib/x86_64-linux-gnu
4+
export OPENCV_H_DIR=/usr/include/opencv4
5+
export LD_LIBRARY_PATH=$SYSTEMC/lib-linux64:$OPENCV_SO_DIR
6+
export USER_DEF_SYSTEMC_DIR=1
7+
export INCLUDE_OPENCV=1

0 commit comments

Comments
 (0)