# Path: python/pipeline/exceptions.py
# class PipelineException(Exception):
#     """Base pipeline exception. Prints the message plus any specific info."""
#     def __init__(self, message, info=None):
#         info_message = '\nError info: ' + repr(info) if info else ''
#         super().__init__(message + info_message)
#         self.info = info


from collections import defaultdict
from itertools import count
from operator import attrgetter
from os import path as op
from tqdm import tqdm
from ..exceptions import PipelineException
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import pickle
    import cv2
import math
                cv2.ellipse(mask, tuple(self._last_ellipse), (255), thickness=cv2.FILLED)
                # cv2.drawContours(mask, [self._last_contour], -1, (255), thickness=cv2.FILLED)
                mask = cv2.dilate(mask, mask_kernel, iterations=self.dilation_iter.value)
                thres *= mask
            thres *= small_mask

            _, contours, hierarchy1 = cv2.findContours(thres.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
            contour, ellipse = self.get_pupil_from_contours(contours, blur, small_mask)

            self._last_ellipse = ellipse

            if contour is None:
                traces.append(dict(frame_id=fr_count, frame_intensity=img_std))
            else:
                eye_center = eye_roi[::-1, 0] + np.asarray(ellipse[0])
                self._center = np.asarray(ellipse[0]) / np.asarray(small_gray.shape[::-1])
                self._radius = max(ellipse[1])

                traces.append(dict(center=eye_center,
                                   major_r=np.max(ellipse[1]),
                                   rotated_rect=np.hstack(ellipse),
                                   contour=contour.astype(np.int16),
                                   frame_id=fr_count,
                                   frame_intensity=img_std
                                   ))
            if display:
                self.display(self._mask * gray if self._mask is not None else gray, blur, thres, eye_roi,
                             fr_count, n_frames, ellipse=ellipse,
                             eye_center=eye_center, contour=contour, ncontours=len(contours))
            if (cv2.waitKey(1) & 0xFF == ord('q')):

# Path: python/pipeline/exceptions.py
# class PipelineException(Exception):
#     """Base pipeline exception. Prints the message plus any specific info."""
#     def __init__(self, message, info=None):
#         info_message = '\nError info: ' + repr(info) if info else ''
#         super().__init__(message + info_message)
#         self.info = info


# Path: python/pipeline/utils/eye_tracking.py
from collections import defaultdict
from itertools import count
from operator import attrgetter
from os import path as op
from tqdm import tqdm
from ..exceptions import PipelineException
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import pickle
    import cv2
import math

                cv2.ellipse(mask, tuple(self._last_ellipse), (255), thickness=cv2.FILLED)
                # cv2.drawContours(mask, [self._last_contour], -1, (255), thickness=cv2.FILLED)
                mask = cv2.dilate(mask, mask_kernel, iterations=self.dilation_iter.value)
                thres *= mask
            thres *= small_mask

            _, contours, hierarchy1 = cv2.findContours(thres.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
            contour, ellipse = self.get_pupil_from_contours(contours, blur, small_mask)

            self._last_ellipse = ellipse

            if contour is None:
                traces.append(dict(frame_id=fr_count, frame_intensity=img_std))
            else:
                eye_center = eye_roi[::-1, 0] + np.asarray(ellipse[0])
                self._center = np.asarray(ellipse[0]) / np.asarray(small_gray.shape[::-1])
                self._radius = max(ellipse[1])

                traces.append(dict(center=eye_center,
                                   major_r=np.max(ellipse[1]),
                                   rotated_rect=np.hstack(ellipse),
                                   contour=contour.astype(np.int16),
                                   frame_id=fr_count,
                                   frame_intensity=img_std
                                   ))
            if display:
                self.display(self._mask * gray if self._mask is not None else gray, blur, thres, eye_roi,
                             fr_count, n_frames, ellipse=ellipse,
                             eye_center=eye_center, contour=contour, ncontours=len(contours))
            if (cv2.waitKey(1) & 0xFF == ord('q')):

                raise PipelineException('Tracking aborted')