Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions MAVProxy/modules/mavproxy_SIYI/tools/img_to_vid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

echo "Converting .bin to .jpg"
~/MAVProxy/MAVProxy/modules/mavproxy_SIYI/tools/temp_dir.py 102SIYI_TEM/ -w

echo "Converting to video. Assuming framerate=5"
ffmpeg -hide_banner -framerate 5 -pattern_type glob -i 'tem_jpg/*.jpg' \
-c:v libx264 -pix_fmt yuv420p output_no_temp.mp4

echo "Adding filenames to .jpgs"
mkdir -p tem_jpg_annotated
for f in tem_jpg/*.jpg; do
f2=${f#*/}
if [ ! -f "tem_jpg_annotated/$f2" ]; then
convert "$f" \
-pointsize 24 \
-fill white \
-undercolor '#00000080' \
-gravity North \
-annotate +0+10 "${f2%.*}" \
"tem_jpg_annotated/$f2"
fi
done

echo "Checking for missed files"
ls tem_jpg > tem_jpg.txt
ls tem_jpg_annotated > tem_jpg_annotated.txt
git diff --no-index tem_jpg.txt tem_jpg_annotated.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why git here, why not just diff?

rm tem_jpg.txt tem_jpg_annotated.txt

echo "Converting to video. Assuming framerate=5"
ffmpeg -hide_banner -framerate 5 -pattern_type glob -i 'tem_jpg_annotated/*.jpg' \
-c:v libx264 -pix_fmt yuv420p output.mp4

62 changes: 46 additions & 16 deletions MAVProxy/modules/mavproxy_SIYI/tools/temp_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
parser.add_argument("--min-temp", default=None, type=float, help="min temperature")
parser.add_argument("--siyi-log", default=None, type=float, help="SIYI binlog")
parser.add_argument("dirname", default=None, type=str, help="directory")
parser.add_argument("-w", "--write", default=False, action='store_true', help="Write the images instead of displaying them")
parser.add_argument("-s", "--startimg", default=0, type=int, help="Image to start with")
args = parser.parse_args()

DNAME=args.dirname
Expand All @@ -38,9 +40,10 @@ def click_callback(event, x, y, flags, param):
mouse_temp = p - C_TO_KELVIN
update_title()

def display_file(fname):
def display_file(fname,w):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def display_file(fname,w):
def display_file(fname, output_filepath=None):

global mouse_temp, tmin, tmax, last_data
print('Importing: ', fname)
if not w:
print('Importing: ', fname)
a = np.fromfile(fname, dtype='>u2')
if len(a) != 640 * 512:
print("Bad size %u" % len(a))
Expand All @@ -59,27 +62,54 @@ def display_file(fname):
if args.min_temp is not None and tmax < args.min_temp:
return

print("Max=%.3fC Min=%.3fC" % (tmax, tmin))
if not w:
print("Max=%.3fC Min=%.3fC" % (tmax, tmin))
if maxv <= minv:
print("Bad range")
return

last_data = a

# convert to 0 to 255
a = (a - minv) * 65535.0 / (maxv - minv)
max_to = 65535.0
if w:
max_to = 255.0
# convert to 0 to 255 or 65535
a = (a - minv) * max_to / (maxv - minv)

# convert to greyscale as 640x512 image
if w:
a = a.astype(np.uint8)
a = a.reshape(512, 640)
if not os.path.exists('tem_jpg'):
os.makedirs('tem_jpg')
jpg_file = 'tem_jpg/'+os.path.basename(fname).removesuffix('.bin')+f"_max{tmax:.1f}_min{tmin:.1f}.jpg"
success = cv2.imwrite(jpg_file,a)
if not success:
print("Failed to write image to "+jpg_file)
exit(1)
else:
a = a.astype(np.uint16)
a = a.reshape(512, 640)
cv2.imshow('Thermal', a)
cv2.setMouseCallback('Thermal', click_callback)
cv2.setWindowTitle('Thermal', "Thermal: (%.1fC to %.1fC) %.1fC" % (tmin, tmax, mouse_temp))
if cv2.waitKey(0) & 0xFF == ord('q'):
exit(0)


# convert to uint8 greyscale as 640x512 image
a = a.astype(np.uint16)
a = a.reshape(512, 640)

cv2.imshow('Thermal', a)
cv2.setMouseCallback('Thermal', click_callback)
cv2.setWindowTitle('Thermal', "Thermal: (%.1fC to %.1fC) %.1fC" % (tmin, tmax, mouse_temp))
flist = sorted(glob.glob(DNAME + "/*bin"))
w = args.write

cv2.waitKey(0)
if not w:
print("Press q to quit. Press any other key to advance to next frame.")

flist = sorted(glob.glob(DNAME + "/*bin"))
if w and os.path.exists('tem_jpg'):
print("tem_jpg directory already exists. Continue? y to continue, anything else to exit.")
rep = input()
if rep != "y":
exit(0)

for f in flist:
display_file(f)
for i in range(args.startimg,len(flist)):
display_file(flist[i],w)
if w and i % 100 == 0:
print(f"Progress: {i}")
Loading