[tracking] tear apart the positions function, offer method to access raw pixel positions
This commit is contained in:
parent
16873702d4
commit
e854ab591f
@ -140,13 +140,14 @@ class MarkerTask():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
print("Hello Jan!")
|
||||||
tank_task = MarkerTask("tank limits", ["bottom left corner", "top left corner", "top right corner", "bottom right corner"], "Mark tank corners")
|
tank_task = MarkerTask("tank limits", ["bottom left corner", "top left corner", "top right corner", "bottom right corner"], "Mark tank corners")
|
||||||
feeder_task = MarkerTask("Feeder positions", list(map(str, range(1, 2))), "Mark feeder positions")
|
#feeder_task = MarkerTask("Feeder positions", list(map(str, range(1, 2))), "Mark feeder positions")
|
||||||
tasks = [tank_task, feeder_task]
|
#tasks = [tank_task, feeder_task]
|
||||||
im = ImageMarker(tasks)
|
im = ImageMarker([tank_task])
|
||||||
# vid1 = "2020.12.11_lepto48DLC_resnet50_boldnessDec11shuffle1_200000_labeled.mp4"
|
vid1 = "/data/personality/secondhome/fischies/lepto_03/position/lepto03_position_2021.06.07_60.mp4"
|
||||||
print(sys.argv[0])
|
# print(sys.argv[0])
|
||||||
print (sys.argv[1])
|
# print (sys.argv[1])
|
||||||
vid1 = sys.argv[1]
|
# vid1 = sys.argv[1]
|
||||||
marker_positions = im.mark_movie(vid1, 10)
|
marker_positions = im.mark_movie(vid1, 00)
|
||||||
print(marker_positions)
|
print(marker_positions)
|
@ -20,7 +20,7 @@ def coordinate_transformation(position,x_0, y_0, x_factor, y_factor):
|
|||||||
return (x, y) #in m
|
return (x, y) #in m
|
||||||
|
|
||||||
class TrackingResult(object):
|
class TrackingResult(object):
|
||||||
|
|
||||||
def __init__(self, results_file, x_0=0, y_0= 0, width_pixel=1230, height_pixel=1100, width_meter=0.81, height_meter=0.81) -> None:
|
def __init__(self, results_file, x_0=0, y_0= 0, width_pixel=1230, height_pixel=1100, width_meter=0.81, height_meter=0.81) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
if not os.path.exists(results_file):
|
if not os.path.exists(results_file):
|
||||||
@ -109,7 +109,11 @@ class TrackingResult(object):
|
|||||||
bp string: the body part
|
bp string: the body part
|
||||||
[type]: [description]
|
[type]: [description]
|
||||||
"""
|
"""
|
||||||
|
time, x, y, l, bp = self.pixel_positions(scorer, bodypart, framerate, interpolate, min_likelihood)
|
||||||
|
x, y = self._to_meter(x, y)
|
||||||
|
return time, x, y, l, bp
|
||||||
|
|
||||||
|
def pixel_positions(self, scorer=0, bodypart=0, framerate=30, interpolate=True, min_likelihood=0.95):
|
||||||
if isinstance(scorer, nb.Number):
|
if isinstance(scorer, nb.Number):
|
||||||
sc = self._scorer[scorer]
|
sc = self._scorer[scorer]
|
||||||
elif isinstance(scorer, str) and scorer in self._scorer:
|
elif isinstance(scorer, str) and scorer in self._scorer:
|
||||||
@ -123,25 +127,37 @@ class TrackingResult(object):
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Bodypart %s is not in dataframe!" % bodypart)
|
raise ValueError("Bodypart %s is not in dataframe!" % bodypart)
|
||||||
|
|
||||||
x = self._data_frame[sc][bp]["x"] if "x" in self._positions else []
|
x = np.asarray(self._data_frame[sc][bp]["x"] if "x" in self._positions else [])
|
||||||
x = (np.asarray(x) - self.x_0) * self.x_factor
|
y = np.asarray(self._data_frame[sc][bp]["y"] if "y" in self._positions else [])
|
||||||
y = self._data_frame[sc][bp]["y"] if "y" in self._positions else []
|
l = np.asarray(self._data_frame[sc][bp]["likelihood"] if "likelihood" in self._positions else [])
|
||||||
y = (np.asarray(y) - self.y_0) * self.y_factor
|
|
||||||
l = self._data_frame[sc][bp]["likelihood"] if "likelihood" in self._positions else []
|
time = np.arange(len(x))/framerate
|
||||||
|
if interpolate:
|
||||||
time = np.arange(len(self._data_frame))/framerate
|
x, y = self.interpolate(time, x, y, l, min_likelihood)
|
||||||
time2 = time[l > min_likelihood]
|
return time, x, y, l, bp
|
||||||
if len(l[l > min_likelihood]) < 100:
|
|
||||||
print("%s has not datapoints with likelihood larger than %.2f" % (self._file_name, min_likelihood) )
|
def _to_meter(self, x, y):
|
||||||
return None, None, None, None, None
|
new_x = (np.asarray(x) - self.x_0) * self.x_factor
|
||||||
|
new_y = (np.asarray(y) - self.y_0) * self.y_factor
|
||||||
|
return new_x, new_y
|
||||||
|
|
||||||
|
def _speed(self, t, x, y):
|
||||||
|
speed = np.sqrt(np.diff(x)**2 + np.diff(y)**2) / np.diff(t)
|
||||||
|
return speed
|
||||||
|
|
||||||
|
def interpolate(self, t, x, y, l, min_likelihood=0.9):
|
||||||
|
time2 = t[l > min_likelihood]
|
||||||
|
if len(l[l > min_likelihood]) < 10:
|
||||||
|
print("%s has less than 10 datapoints with likelihood larger than %.2f" % (self._file_name, min_likelihood) )
|
||||||
|
return None, None
|
||||||
x2 = x[l > min_likelihood]
|
x2 = x[l > min_likelihood]
|
||||||
y2 = y[l > min_likelihood]
|
y2 = y[l > min_likelihood]
|
||||||
x3 = np.interp(time, time2, x2)
|
x3 = np.interp(t, time2, x2)
|
||||||
y3 = np.interp(time, time2, y2)
|
y3 = np.interp(t, time2, y2)
|
||||||
return time, x3, y3, l, bp
|
return x3, y3
|
||||||
|
|
||||||
def plot(self, scorer=0, bodypart=0, threshold=0.9, framerate=30):
|
def plot(self, scorer=0, bodypart=0, threshold=0.9, framerate=30):
|
||||||
t, x, y, l, name = self.position_values(scorer=scorer, bodypart=bodypart, framerate=framerate)
|
t, x, y, l, name = self.position_values(scorer=scorer, bodypart=bodypart, framerate=framerate, min_likelihood=threshold)
|
||||||
plt.scatter(x[l > threshold], y[l > threshold], c=t[l > threshold], label=name)
|
plt.scatter(x[l > threshold], y[l > threshold], c=t[l > threshold], label=name)
|
||||||
plt.scatter(self.center_meter[0], self.center_meter[1], marker="*")
|
plt.scatter(self.center_meter[0], self.center_meter[1], marker="*")
|
||||||
plt.plot(x[l > threshold], y[l > threshold])
|
plt.plot(x[l > threshold], y[l > threshold])
|
||||||
@ -152,7 +168,6 @@ class TrackingResult(object):
|
|||||||
bar.set_label("time [s]")
|
bar.set_label("time [s]")
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.show()
|
plt.show()
|
||||||
from IPython import embed
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user