Merge branch 'main' of https://whale.am28.uni-tuebingen.de/git/jgrewe/fixtracks
This commit is contained in:
commit
5eb53e4b0b
76
fixtracks/read_tracks.py
Normal file
76
fixtracks/read_tracks.py
Normal file
@ -0,0 +1,76 @@
|
||||
import json
|
||||
import cv2 as cv
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from IPython import embed
|
||||
|
||||
def show_video(filename):
|
||||
cap = cv.VideoCapture('2024.11.13_0_converted_right_undistorted_fixed.mp4')
|
||||
count = 0
|
||||
while cap.isOpened():
|
||||
ret, frame = cap.read()
|
||||
# if frame is read correctly ret is True
|
||||
if not ret:
|
||||
print("Can't receive frame (stream end?). Exiting ...")
|
||||
break
|
||||
count += 1
|
||||
if count < 2000:
|
||||
continue
|
||||
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
|
||||
print(count)
|
||||
cv.imshow('frame', gray[::2,::2])
|
||||
if cv.waitKey(1) == ord('q'):
|
||||
break
|
||||
cap.release()
|
||||
cv.destroyAllWindows()
|
||||
|
||||
def topandas(filename):
|
||||
temp = []
|
||||
tracking_data = {"frame": [], "name": [], "cls": [],
|
||||
"confidence": [], "visible": [] ,
|
||||
"track_id": [],
|
||||
}
|
||||
key_dict = {f"key_{i}": [] for i in range(6)}
|
||||
box_labels = ["x1", "y1", "x2", "y2"]
|
||||
box_dict = {f"box_{i}": [] for i in box_labels}
|
||||
tracking_data.update(key_dict)
|
||||
tracking_data.update(box_dict)
|
||||
|
||||
with open(filename, "r") as f:
|
||||
data = json.load(f)
|
||||
for d in data: # each of the frames
|
||||
if len(d["data"]) == 0:
|
||||
continue
|
||||
for dd in d["data"]: # each of the found objects, i.e. fish
|
||||
key_x = [float(x) for x in list(np.round(dd["keypoints"]["x"], 2))]
|
||||
key_y = [float(y) for y in list(np.round(dd["keypoints"]["y"], 2))]
|
||||
key_dict = {f"key_{i}": [v] for i, v in enumerate(zip(key_x, key_y))}
|
||||
visible = np.round(dd["keypoints"]["visible"], 3)
|
||||
tracking_data["frame"].append(d["frame"])
|
||||
tracking_data["name"].append(dd["name"])
|
||||
tracking_data["cls"].append(dd["class"])
|
||||
tracking_data["visible"].append(visible)
|
||||
tracking_data["confidence"].append(float(np.round(dd["confidence"], 3)))
|
||||
tracking_data["track_id"].append(dd["track_id"] if "track_id" in dd.keys() else -1)
|
||||
for bk, bl in zip(box_dict.keys(), box_labels):
|
||||
tracking_data[bk].append(dd["box"][bl])
|
||||
for i, kd in enumerate(key_dict.keys()):
|
||||
tracking_data[kd].append((key_x[i], key_y[i]))
|
||||
|
||||
df = pd.DataFrame(tracking_data)
|
||||
return df
|
||||
|
||||
def main():
|
||||
# import left and right tracks into a pandas dataframe
|
||||
right_tracks = "2024.11.13_0_converted_right_undistorted_fixed_pose.json"
|
||||
left_tracks = "2024.11.13_0_converted_left_undistorted_fixed_pose.json"
|
||||
|
||||
rdf = topandas(right_tracks)
|
||||
rdf.to_csv("right_tracks.csv", sep=";")
|
||||
ldf = topandas(left_tracks)
|
||||
ldf.to_csv("left_tracks.csv", sep=";")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
BIN
icons/Unbenannt.afdesign
Normal file
BIN
icons/Unbenannt.afdesign
Normal file
Binary file not shown.
BIN
icons/convert.png
Normal file
BIN
icons/convert.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
icons/merge.png
Normal file
BIN
icons/merge.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
BIN
icons/open.png
Normal file
BIN
icons/open.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
icons/tracks.png
Normal file
BIN
icons/tracks.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -4,7 +4,10 @@
|
||||
<file alias="help">icons/help.png</file>
|
||||
<file alias="quit">icons/quit.png</file>
|
||||
<file alias="close">icons/nix_close.png</file>
|
||||
<file alias="open">icons/nix_open.png</file>
|
||||
<file alias="open">icons/open.png</file>
|
||||
<file alias="merge">icons/merge.png</file>
|
||||
<file alias="convert">icons/convert.png</file>
|
||||
<file alias="tracks">icons/tracks.png</file>
|
||||
<file alias="settings">icons/settings.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
Loading…
Reference in New Issue
Block a user