예제 #1
0
    def check_skeleton(self, skeleton: dict):
        """
        Checking skeleton for trigger
        :param skeleton: a skeleton dictionary, returned by calculate_skeletons() from poser file
        :return: response, a tuple of result (bool) and response body
        Response body is used for plotting and outputting results to trials dataframes
        """
        # choosing a point to draw near the skeleton
        org_point = skeleton[list(skeleton.keys())[0]]
        joint_moved = []
        if self._skeleton is None:
            result = False
            text = 'Not freezing'
            self._skeleton = skeleton
        else:
            for joint in skeleton:
                joint_travel = calculate_distance(skeleton[joint], self._skeleton[joint])
                joint_moved.append(abs(joint_travel) <= self._threshold)
            if all(joint_moved):
                result = True
                text = 'Freezing'
            else:
                result = False
                text = 'Not freezing'
            self._skeleton = skeleton

        color = (0, 255, 0) if result else (0, 0, 255)
        response_body = {'plot': {'text': dict(text=text,
                                               org=org_point,
                                               color=color)}}
        response = (result, response_body)
        return response
예제 #2
0
 def calculate_closest_distances(dots_cluster: list) -> float:
     """
     Calculating a sum of all distances between all dots in a cluster
     """
     # extracting dots coordinates from given list
     dots_coordinates = (dot[0] for dot in dots_cluster)
     # calculating sum of each dots cluster
     product_sum = sum(calculate_distance(*c) for c in combinations(dots_coordinates, 2))
     return product_sum
예제 #3
0
    def check_skeleton(self, skeleton: dict):
        """
        Checking skeleton for trigger
        :param skeleton: a skeleton dictionary, returned by calculate_skeletons() from poser file
        :return: response, a tuple of result (bool) and response body
        Response body is used for plotting and outputting results to trials dataframes
        """
        # choosing a point to draw near the skeleton
        org_point = skeleton[list(skeleton.keys())[0]]
        joint_moved = 0

        if self._skeleton is None:
            result = False
            text = "..."
            self._skeleton = skeleton
        else:
            joint_travel = calculate_distance(skeleton[self._bodypart],
                                              self._skeleton[self._bodypart])
            self._timewindow.append(joint_travel)
            if len(self._timewindow) == self._timewindow_len:
                joint_moved = np.sum(self._timewindow)

            if abs(joint_moved) >= self._threshold:
                result = True
                text = "Running"
            else:
                result = False
                text = "Not Running"
        self._skeleton = skeleton
        color = (0, 255, 0) if result else (0, 0, 255)
        response_body = {
            "plot": {
                "text": dict(text=text, org=org_point, color=color)
            }
        }
        response = (result, response_body)

        return response
예제 #4
0
    def check_skeleton(self, skeletons: dict):
        """
        Checking skeletons for trigger
        :param skeletons: a skeleton dictionary, returned by calculate_skeletons() from poser file
        :return: response, a tuple of result (bool) and response body
        Response body is used for plotting and outputting results to trials dataframes
        """

        results = []
        for active_bp in self._identification_dict['active']['bp']:
            active_coords = skeletons[self._active_animal][active_bp]
            for passive_bp in self._identification_dict['passive']['bp']:
                passive_coords = skeletons[self._passive_animal][passive_bp]
                temp_result = False
                #calculate distance for all combinations if none of the coordinates are NaN
                if not any(np.isnan([*active_coords, *passive_coords])):
                    distance = calculate_distance(active_coords,
                                                  passive_coords)
                    if distance >= self._threshold and self._interaction_type == 'distance':
                        temp_result = True
                    elif distance < self._threshold and self._interaction_type == 'proximity':
                        temp_result = True
                    else:
                        pass
                else:
                    pass

                results.append(temp_result)

        result = any(results)

        color = (0, 255, 0) if result else (0, 0, 255)

        if self._debug:
            active_point_x, active_point_y = skeletons[self._active_animal][
                self._active_bp[0]]
            passive_point_x, passive_point_y = skeletons[self._passive_animal][
                self._passive_bp[0]]
            if not any(
                    np.isnan([
                        active_point_x, active_point_y, passive_point_x,
                        passive_point_y
                    ])):
                response_body = {
                    'plot': {
                        'text':
                        dict(text=f'{self._interaction_type}: {result}',
                             org=(20, 20),
                             color=color),
                        'line':
                        dict(pt1=(int(active_point_x), int(active_point_y)),
                             pt2=(int(passive_point_x), int(passive_point_y)),
                             color=color),
                    }
                }
            else:
                response_body = {
                    'plot': {
                        'text':
                        dict(text=f'{self._interaction_type}: {result}',
                             org=(20, 20),
                             color=color)
                    }
                }

        else:
            response_body = {
                'plot': {
                    'text':
                    dict(text=f'{self._interaction_type}: {result}',
                         org=(20, 20),
                         color=color)
                }
            }
        response = (result, response_body)
        return response