cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_harris_numpi.py
Go to the documentation of this file.
1 # *****************************************************************************
2 # * cloudFPGA
3 # * Copyright 2016 -- 2022 IBM Corporation
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 
24 
25 import sys
26 import os
27 import numpy as np
28 import cv2
29 
30 trieres_lib=os.environ['cFpRootDir'] + "HOST/vision/harris/languages/python/build"
31 sys.path.append(trieres_lib)
32 
33 import _trieres_harris_numpi
34 
35 # size of image to be processed on fpga (the bitstream should be already fixed to this)
36 height = width = 256
37 
38 num_frame = 1
39 
40 # path
41 image_in_filename = os.environ['cFpRootDir'] + "ROLE/vision/hls/harris/test/512x512.png"
42 image_out_filename = image_in_filename + "_fpga_points_out_frame_" + str(num_frame) + ".png"
43 
44 for i in range(10):
45  # Reading an image in unchanged mode
46  image = cv2.imread(image_in_filename, cv2.IMREAD_UNCHANGED)
47 
48  # Converting to grayscale
49  image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
50 
51  # Adjusting the image file if needed
52  if ((image.shape[0] != height) or (image.shape[1] != width)):
53  print("WARNING: The image was resized from [", image.shape[0] , " x ", image.shape[1] , "] to [", height , " x ", width, "]")
54  dim = (width, height)
55  image = cv2.resize(image, dim, interpolation = cv2.INTER_LINEAR)
56 
57  # Flattening the image from 2D to 1D
58  image = image.flatten()
59 
60  total_size = height * width
61 
62  input_array = image
63 
64 #for i in range(100):
65 
66  output_array = _trieres_harris_numpi.harris(input_array, total_size, "10.12.200.234", "2719")
67 
68  # Convert 1D array to a 2D numpy array of 2 rows and 3 columns
69  output_array_2d = np.reshape(output_array, (height, width))
70 
71 cv2.imwrite(image_out_filename, output_array_2d)
72 print("INFO: the output file is saved at : " + image_out_filename)