31 trieres_lib=os.environ[
'cFpRootDir'] +
"HOST/"
32 sys.path.append(trieres_lib)
34 from trieres
import vision
36 config_file=os.environ[
'cFpRootDir'] +
"HOST/vision/median_blur/languages/cplusplus/include/config.h"
38 with open(config_file)
as cfg:
40 if "#define FRAME_WIDTH" in line:
41 width =
int(line.split()[2])
42 elif "#define FRAME_HEIGHT" in line:
43 height =
int(line.split()[2])
45 print(
"Found in " + config_file +
": width = "+
str(width) +
", height = "+
str(height))
46 total_size = height * width
48 print(
"Coudln't find FRAME_WIDTH or FRAME_HEIGHT in "+ config_file +
". Aborting...")
54 image_in_filename = os.environ[
'cFpRootDir'] +
"ROLE/vision/hls/harris/test/512x512.png"
55 image_out_filename = image_in_filename +
"_fpga_points_out_frame_" +
str(num_frame) +
".png"
64 min_size = np.amin([h,w])
65 print(
"min_size="+
str(min_size))
68 crop_img = img[
int(h/2-min_size/2):
int(h/2+min_size/2),
int(w/2-min_size/2):
int(w/2+min_size/2)]
73 roi = crop_img[y1:y2, x1:x2]
74 resized = cv2.resize(roi , (size, size), interpolation=interpolation)
83 min_size = np.amin([h,w])
84 print(
"min_size="+
str(min_size))
87 img[
int(h/2-min_size/2):
int(h/2+min_size/2),
int(w/2-min_size/2):
int(w/2+min_size/2)] = crop_img
96 image = cv2.imread(image_in_filename, cv2.IMREAD_UNCHANGED)
99 image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
102 if ((image.shape[0] != height)
or (image.shape[1] != width)):
104 print(
"WARNING: An image of size [", height ,
" x ", width,
"] will be cropped from input image of size [", image.shape[0] ,
" x ", image.shape[1] ,
"]")
106 image =
crop_square(image_big, width, interpolation = cv2.INTER_AREA)
108 print(
"WARNING: The image was resized from [", image.shape[0] ,
" x ", image.shape[1] ,
"] to [", height ,
" x ", width,
"]")
109 dim = (width, height)
110 image = cv2.resize(image, dim, interpolation = cv2.INTER_LINEAR)
113 image = image.flatten()
115 total_size = height * width
124 output_array_2d = np.reshape(output_array, (height, width))
129 cv2.imwrite(image_out_filename, output_array_2d)
130 print(
"INFO: the output file is saved at : " + image_out_filename)
def median_blur(input_array, total_size, fpga_ip, fpga_port, debug_level)