-
Notifications
You must be signed in to change notification settings - Fork 738
mavproxy_SIYI: Tool to convert thermal files to video #1631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MichelleRos
wants to merge
1
commit into
ArduPilot:master
Choose a base branch
from
MichelleRos:pr/thermal_vid
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
|
@@ -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): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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)) | ||||||
|
@@ -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}") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 justdiff
?