Skip to content

Commit

Permalink
more waterfall rendering improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
anarkiwi committed Jan 7, 2024
1 parent 1cd08d9 commit 936e74b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 33 deletions.
42 changes: 21 additions & 21 deletions auto_label/auto_label.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
import os
import os
from argparse import ArgumentParser
import numpy as np
import numpy as np
import cv2 as cv



def label(filename):

img = cv.imread(filename)
imgray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

# opening and closing
# https://docs.opencv.org/3.4/d9/d61/tutorial_py_morphological_ops.html
# https://docs.opencv.org/3.4/d3/dbe/tutorial_opening_closing_hats.html
kernel = np.ones((5,5),np.uint8)
kernel = np.ones((5, 5), np.uint8)
imgray = cv.morphologyEx(imgray, cv.MORPH_OPEN, kernel)
imgray = cv.morphologyEx(imgray, cv.MORPH_CLOSE, kernel)


# bilateral smoothing
# https://docs.opencv.org/3.4/dc/dd3/tutorial_gausian_median_blur_bilateral_filter.html
bilateral_kernel = 8
imgray = cv.bilateralFilter(imgray, bilateral_kernel, bilateral_kernel * 2, bilateral_kernel / 2)
imgray = cv.bilateralFilter(
imgray, bilateral_kernel, bilateral_kernel * 2, bilateral_kernel / 2
)
ret, thresh = cv.threshold(imgray, 140, 255, 0)
contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
# remove internal contours

# remove internal contours
# https://docs.opencv.org/4.x/d9/d8b/tutorial_py_contours_hierarchy.html
good_contours = []
for i in range(len(contours)):
if hierarchy[0,i,3] == -1:
if hierarchy[0, i, 3] == -1:
good_contours.append(contours[i])
contours = good_contours

# draw rectangels over all contours
# draw rectangels over all contours
for cnt in contours:
# Contour approximation https://docs.opencv.org/4.x/dd/d49/tutorial_py_contour_features.html
# epsilon = 0.01*cv.arcLength(cnt,True)
Expand All @@ -42,14 +41,14 @@ def label(filename):
# Convex hull
# cnt = cv.convexHull(cnt)

x,y,w,h = cv.boundingRect(cnt)
cv.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)

x, y, w, h = cv.boundingRect(cnt)
cv.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)

cv.imshow('Image',img)
cv.imshow("Image", img)
cv.waitKey(0)
cv.destroyAllWindows()


def main():
parser = ArgumentParser()
parser.add_argument(
Expand All @@ -62,20 +61,21 @@ def main():

filepath = args.filepath

# get files
# get files
files = []
if os.path.isfile(filepath):
files.append(filepath)
elif os.path.isdir(filepath):
files.extend([os.path.join(filepath, filename) for filename in os.listdir(filepath)])
files.extend(
[os.path.join(filepath, filename) for filename in os.listdir(filepath)]
)
else:
raise ValueError('filepath must be existing directory or filename')
raise ValueError("filepath must be existing directory or filename")

# loop through files
for img_filename in files:
label(img_filename)



if __name__ == "__main__":
main()
main()
19 changes: 11 additions & 8 deletions gamutrflib/gamutrflib/zmqbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ def read_buff(self, log, discard_time):
lines = self.txtbuf_to_lines(log)
if lines:
df = self.lines_to_df(lines)
scan_config, frame_df = self.read_new_frame_df(df, discard_time)
if df is not None:
scan_config, frame_df = self.read_new_frame_df(df, discard_time)
return scan_config, frame_df


Expand Down Expand Up @@ -266,15 +267,17 @@ def healthy(self):

def read_buff(self, log=None, discard_time=0, scan_fres=0):
while True:
results = [scanner.read_buff(log, discard_time) for scanner in self.scanners]
results = [
scanner.read_buff(log, discard_time) for scanner in self.scanners
]
new_results = 0
if self.last_results:
for i, result in enumerate(results):
_scan_config, df = result
if df is not None:
self.last_results[i] = result
new_results += 1
logging.info("%s got scan result", self.scanners[i])
for i, result in enumerate(results):
_scan_config, df = result
if df is not None:
self.last_results[i] = result
new_results += 1
logging.info("%s got scan result", self.scanners[i])

Check warning on line 280 in gamutrflib/gamutrflib/zmqbucket.py

View check run for this annotation

Codecov / codecov/patch

gamutrflib/gamutrflib/zmqbucket.py#L275-L280

Added lines #L275 - L280 were not covered by tests
else:
self.last_results = results
if new_results == 0:
Expand Down
8 changes: 6 additions & 2 deletions gamutrfwaterfall/gamutrfwaterfall/waterfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,10 +988,16 @@ def sig_handler(_sig=None, _frame=None):
need_reset_fig = False
last_gap = time.time()
while True:
gap_time = time.time() - last_gap
if results and gap_time > refresh / 2:
break
scan_configs, scan_df = zmqr.read_buff(
scan_fres=config.freq_resolution * 1e6
)
if scan_df is None:
if batch and gap_time < refresh / 2:
time.sleep(0.1)
continue
break
last_config = make_config(
scan_configs,
Expand Down Expand Up @@ -1024,8 +1030,6 @@ def sig_handler(_sig=None, _frame=None):
)
continue
results.append((scan_configs, scan_df))
if results and time.time() - last_gap > (refresh / 2):
break
if need_reconfig:
continue
if results:
Expand Down
2 changes: 1 addition & 1 deletion orchestrator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ services:
- --inference_model_name=mini2_snr
- --n_inference=10
- --n_image=10
- --vkfft
- --no-vkfft
# - --external_gps_server=1.2.3.4
# - --external_gps_server_port=8888
# - --inference_output_dir=/logs/inference
Expand Down
4 changes: 3 additions & 1 deletion tests/test_grscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def test_fake_uhd(self):
get_source("ettus", 1e3, 10, 1024, 1024, uhd_lib=FakeUHD())

def test_fake_soapy(self):
sources, _, workaround = get_source("SoapyAIRT", 1e3, 10, 1024, 1024, soapy_lib=FakeSoapy())
sources, _, workaround = get_source(
"SoapyAIRT", 1e3, 10, 1024, 1024, soapy_lib=FakeSoapy()
)
tb = FakeTb(sources, workaround, 100e6)
tb.start()

Expand Down

0 comments on commit 936e74b

Please sign in to comment.