Skip to content

Commit 92d07b5

Browse files
SDA USRsdausr
authored andcommitted
Squashed 'vision' changes from bf6131ae6..744f8cf5b (#1141)
744f8cf5b Merge pull request #793 from nvunnam/next_v1 5d2968e62 create master branch from next branch Co-authored-by: sdausr <[email protected]>
1 parent 1db9f57 commit 92d07b5

File tree

199 files changed

+3973417
-1600232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+3973417
-1600232
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2022 Xilinx, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef _XF_GC_CONFIG_H_
18+
#define _XF_GC_CONFIG_H_
19+
20+
#include "common/xf_common.hpp"
21+
#include "hls_stream.h"
22+
#include "imgproc/xf_duplicateimage.hpp"
23+
#include "imgproc/xf_agc.hpp"
24+
#include "imgproc/xf_autowhitebalance.hpp"
25+
26+
#include <ap_int.h>
27+
28+
#define NPPCX XF_NPPC1
29+
30+
#define T_8U 0
31+
#define T_16U 1
32+
33+
#if T_8U
34+
#define HIST_SIZE 256
35+
#endif
36+
#if T_10U
37+
#define HIST_SIZE 1024
38+
#endif
39+
#if T_16U || T_12U
40+
#define HIST_SIZE 4096
41+
#endif
42+
43+
#if T_8U
44+
#define IN_TYPE XF_8UC3
45+
#elif T_16U
46+
#define IN_TYPE XF_16UC3
47+
#endif
48+
49+
void autogaincontrol_accel(unsigned int histogram[XF_CHANNELS(IN_TYPE, NPPCX)][HIST_SIZE],
50+
uint16_t gain[XF_CHANNELS(IN_TYPE, NPPCX)]);
51+
#endif
52+
_XF_GC_CONFIG_H_
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "Xilinx autogaincontrol Test",
3+
"description": "HLS case",
4+
"flow": "hls",
5+
"platform_allowlist": [
6+
"u200",
7+
"u50",
8+
"zcu102",
9+
"zcu104",
10+
"aws-vu9p-f1",
11+
"vck190"
12+
],
13+
"platform_blocklist": [],
14+
"part_allowlist": [],
15+
"part_blocklist": [],
16+
"project": "autogaincontrol",
17+
"solution": "sol1",
18+
"clock": "3.3",
19+
"topfunction": "autogaincontrol_accel",
20+
"top": {
21+
"source": [
22+
"${XF_PROJ_ROOT}/L1/examples/autogaincontrol/xf_autogaincontrol_accel.cpp"
23+
],
24+
"cflags": " -I ${XF_PROJ_ROOT}/L1/examples/autogaincontrol/config -I${XF_PROJ_ROOT}/L1/include -I ./ -D__SDSVHLS__ -std=c++0x",
25+
"csimflags": " -I ${XF_PROJ_ROOT}/L1/examples/autogaincontrol/config -I${XF_PROJ_ROOT}/L1/include -I ./ -D__SDSVHLS__ -std=c++0x"
26+
},
27+
"testbench": {
28+
"source": [
29+
"${XF_PROJ_ROOT}/L1/examples/autogaincontrol/xf_autogaincontrol_tb.cpp"
30+
],
31+
"cflags": " -I ${XF_PROJ_ROOT}/L1/examples/autogaincontrol/config -I${OPENCV_INCLUDE} -I${XF_PROJ_ROOT}/L1/include -I ./ -D__SDSVHLS__ -std=c++0x",
32+
"ldflags": "-L ${OPENCV_LIB} -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_flann -lopencv_features2d",
33+
"argv": {
34+
"hls_csim": " ${XF_PROJ_ROOT}/data/128x128.png ",
35+
"hls_cosim": " ${XF_PROJ_ROOT}/data/128x128.png "
36+
},
37+
"stdmath": false,
38+
"csimflags": " -I ${XF_PROJ_ROOT}/L1/examples/autogaincontrol/config -I${XF_PROJ_ROOT}/L1/include -I ./ -D__SDSVHLS__ -std=c++0x"
39+
},
40+
"testinfo": {
41+
"disable": false,
42+
"jobs": [
43+
{
44+
"index": 0,
45+
"dependency": [],
46+
"env": "",
47+
"cmd": "",
48+
"max_memory_MB": {
49+
"vivado_syn": 16384,
50+
"hls_csim": 10240,
51+
"hls_cosim": 16384,
52+
"vivado_impl": 16384,
53+
"hls_csynth": 10240
54+
},
55+
"max_time_min": {
56+
"vivado_syn": 300,
57+
"hls_csim": 60,
58+
"hls_cosim": 300,
59+
"vivado_impl": 300,
60+
"hls_csynth": 60
61+
}
62+
}
63+
],
64+
"targets": [
65+
"hls_csim",
66+
"hls_csynth",
67+
"hls_cosim",
68+
"vivado_syn",
69+
"vivado_impl"
70+
],
71+
"category": "canary"
72+
},
73+
"gui": true
74+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[hls]
2+
3+
clock=3.3
4+
flow_target=vivado
5+
syn.file=${XF_PROJ_ROOT}/L1/examples/autogaincontrol/xf_autogaincontrol_accel.cpp
6+
syn.file_cflags=${XF_PROJ_ROOT}/L1/examples/autogaincontrol/xf_autogaincontrol_accel.cpp, -I ${XF_PROJ_ROOT}/L1/examples/autogaincontrol/config -I${XF_PROJ_ROOT}/L1/include -I ./ -D__SDSVHLS__ -std=c++0x
7+
syn.file_csimflags=${XF_PROJ_ROOT}/L1/examples/autogaincontrol/xf_autogaincontrol_accel.cpp, -I ${XF_PROJ_ROOT}/L1/examples/autogaincontrol/config -I${XF_PROJ_ROOT}/L1/include -I ./ -D__SDSVHLS__ -std=c++0x
8+
syn.top=autogaincontrol_accel
9+
tb.file=${XF_PROJ_ROOT}/L1/examples/autogaincontrol/xf_autogaincontrol_tb.cpp
10+
tb.file_cflags=${XF_PROJ_ROOT}/L1/examples/autogaincontrol/xf_autogaincontrol_tb.cpp, -I ${XF_PROJ_ROOT}/L1/examples/autogaincontrol/config -I${OPENCV_INCLUDE} -I${XF_PROJ_ROOT}/L1/include -I ./ -D__SDSVHLS__ -std=c++0x
11+
tb.file_csimflags=${XF_PROJ_ROOT}/L1/examples/autogaincontrol/xf_autogaincontrol_tb.cpp, -I ${XF_PROJ_ROOT}/L1/examples/autogaincontrol/config -I${XF_PROJ_ROOT}/L1/include -I ./ -D__SDSVHLS__ -std=c++0x
12+
13+
csim.argv= ${XF_PROJ_ROOT}/data/ltm_input_128x128.png
14+
csim.ldflags=-L ${OPENCV_LIB} -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_flann -lopencv_features2d
15+
16+
cosim.argv= ${XF_PROJ_ROOT}/data/ltm_input_128x128.png
17+
cosim.ldflags=-L ${OPENCV_LIB} -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_flann -lopencv_features2d
18+
19+
20+
21+
vivado.flow=${VIVADO_FLOW}
22+
vivado.rtl=verilog
23+
sim.ldflags=-L ${OPENCV_LIB} -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_flann -lopencv_features2d
24+
25+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2022 Xilinx, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "xf_autogaincontrol_accel_config.h"
18+
static bool flag = 0;
19+
20+
void autogaincontrol_accel(unsigned int histogram[XF_CHANNELS(IN_TYPE, NPPCX)][HIST_SIZE],
21+
uint16_t gain[XF_CHANNELS(IN_TYPE, NPPCX)]) {
22+
// clang-format off
23+
24+
#pragma HLS INTERFACE s_axilite port=histogram bundle=control
25+
#pragma HLS INTERFACE s_axilite port=gain bundle=control
26+
#pragma HLS INTERFACE s_axilite port=return bundle=control
27+
// clang-format on
28+
xf::cv::autogain<IN_TYPE, NPPCX, HIST_SIZE>(histogram, gain);
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2022 Xilinx, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "xf_config_params.h"
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Copyright 2022 Xilinx, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "common/xf_headers.hpp"
18+
#include "xf_autogaincontrol_tb_config.h"
19+
20+
#include <time.h>
21+
22+
void autogainControlref(cv::Mat& input,
23+
unsigned int histogram[3][HIST_SIZE],
24+
unsigned int* rgain,
25+
unsigned int* bgain,
26+
unsigned int* ggain) {
27+
#if T_8U
28+
float inputMin = 0.0f;
29+
float inputMax = 255.0f;
30+
float outputMin = 0.0f;
31+
float outputMax = 255.0f;
32+
unsigned int gain = 256;
33+
#else
34+
float inputMin = 0.0f;
35+
float inputMax = 65535.0f;
36+
float outputMin = 0.0f;
37+
float outputMax = 65535.0f;
38+
unsigned int gain = 65536;
39+
#endif
40+
41+
std::cout << "started autogaincontrol" << std::endl;
42+
int bins = HIST_SIZE; // number of bins at each histogram level
43+
const int GAIN_ARRAY_SIZE = HIST_SIZE / 32; // histogram is divided into cluster of size 32bins each
44+
45+
std::cout << "GAIN_ARRAY_SIZE is " << GAIN_ARRAY_SIZE << std::endl;
46+
unsigned int gain_array[GAIN_ARRAY_SIZE] = {
47+
0}; // Sample for gain_array values for 8bit {256,224,192,160,128,96,64,32}
48+
49+
int temp_gain = gain;
50+
for (int i = 0; i < GAIN_ARRAY_SIZE; i++) {
51+
gain_array[i] = temp_gain;
52+
temp_gain = temp_gain - 32;
53+
}
54+
55+
unsigned int hist_cluster_of_32bins[3][GAIN_ARRAY_SIZE] = {0};
56+
int gain_range_r = 0;
57+
int gain_range_g = 0;
58+
int gain_range_b = 0;
59+
unsigned int max_hist_cluster_of_32bins_r = 0;
60+
unsigned int max_hist_cluster_of_32bins_g = 0;
61+
unsigned int max_hist_cluster_of_32bins_b = 0;
62+
float minValue = inputMin - 0.5f;
63+
float maxValue = inputMax + 0.5f;
64+
float interval = float(maxValue - minValue) / bins;
65+
66+
for (int y = 0; y < input.rows; ++y) {
67+
for (int x = 0; x < input.cols; ++x) {
68+
#if T_8U
69+
int in_r = input.at<cv::Vec3b>(y, x)[0];
70+
int in_g = input.at<cv::Vec3b>(y, x)[1];
71+
int in_b = input.at<cv::Vec3b>(y, x)[2];
72+
#elif T_16U
73+
unsigned int in_r = input.at<cv::Vec3w>(y, x)[0];
74+
unsigned int in_g = input.at<cv::Vec3w>(y, x)[1];
75+
unsigned int in_b = input.at<cv::Vec3w>(y, x)[2];
76+
#endif
77+
unsigned int currentBin_r = (in_r / interval);
78+
unsigned int currentBin_g = (in_g / interval);
79+
unsigned int currentBin_b = (in_b / interval);
80+
histogram[0][currentBin_r] = histogram[0][currentBin_r] + 1;
81+
histogram[1][currentBin_g] = histogram[1][currentBin_g] + 1;
82+
histogram[2][currentBin_b] = histogram[2][currentBin_b] + 1;
83+
}
84+
}
85+
86+
int hist_count = 0;
87+
for (int i = 0; i < GAIN_ARRAY_SIZE; i++) {
88+
for (int j = 0; j < 32; j++) {
89+
hist_cluster_of_32bins[0][i] += histogram[0][hist_count];
90+
hist_cluster_of_32bins[1][i] += histogram[1][hist_count];
91+
hist_cluster_of_32bins[2][i] += histogram[2][hist_count++];
92+
}
93+
if (hist_cluster_of_32bins[0][gain_range_r] <= hist_cluster_of_32bins[0][i]) {
94+
gain_range_r = i;
95+
}
96+
if (hist_cluster_of_32bins[1][gain_range_g] <= hist_cluster_of_32bins[1][i]) {
97+
gain_range_g = i;
98+
}
99+
if (hist_cluster_of_32bins[2][gain_range_b] <= hist_cluster_of_32bins[2][i]) {
100+
gain_range_b = i;
101+
}
102+
}
103+
104+
*rgain = gain_array[gain_range_r];
105+
*ggain = gain_array[gain_range_g];
106+
*bgain = gain_array[gain_range_b];
107+
}
108+
109+
int main(int argc, char** argv) {
110+
if (argc != 2) {
111+
fprintf(stderr, "Invalid Number of Arguments!\nUsage:\n");
112+
fprintf(stderr, "<Executable Name> <input image path1> \n");
113+
return -1;
114+
}
115+
116+
cv::Mat in_img, ocv_ref, out_gray, diff;
117+
#if T_8U
118+
in_img = cv::imread(argv[1], 1); // read image
119+
#else
120+
in_img = cv::imread(argv[1], -1); // read image
121+
#endif
122+
if (in_img.data == NULL) {
123+
fprintf(stderr, "Cannot open image %s\n", argv[1]);
124+
return -1;
125+
}
126+
127+
int height = in_img.rows;
128+
int width = in_img.cols;
129+
130+
unsigned int rgain_tb = 0;
131+
unsigned int bgain_tb = 0;
132+
unsigned int ggain_tb = 0;
133+
134+
uint16_t gain[XF_CHANNELS(IN_TYPE, NPPCX)] = {0};
135+
136+
// OpenCV Reference
137+
unsigned int histogram[XF_CHANNELS(IN_TYPE, NPPCX)][HIST_SIZE] = {0};
138+
139+
autogainControlref(in_img, histogram, &rgain_tb, &bgain_tb, &ggain_tb);
140+
141+
std::cout << "rgain is " << rgain_tb << std::endl;
142+
std::cout << "ggain is " << ggain_tb << std::endl;
143+
std::cout << "bgain is " << bgain_tb << std::endl;
144+
145+
///////////////////////////Top function call ///////////////////////////
146+
147+
autogaincontrol_accel(histogram, gain);
148+
149+
std::cout << "rgain_kernel is " << gain[0] << std::endl;
150+
std::cout << "ggain_kernel is " << gain[1] << std::endl;
151+
std::cout << "bgain_kernel is " << gain[2] << std::endl;
152+
153+
imwrite("in_img.png", in_img);
154+
std::cout << "autogainControlref is done" << std::endl;
155+
156+
return 0;
157+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2022 Xilinx, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "xf_config_params.h"

0 commit comments

Comments
 (0)