Beispiel #1
0
def calc_drag_coefficient_list(droplet: Droplet, func_name: str,
                               list_Rep: List):
    list_Cd = []
    for Rep in list_Rep:
        droplet.Rep = Rep
        method_to_call = getattr(droplet, func_name)
        list_Cd.append(method_to_call())
    return list_Cd
Beispiel #2
0
 def dict_to_drop(self, dict_of_droplets):
     """Convertion du dict en haut en un format Droplet.
      C'est la classe Droplet qui sera intégré dans les analyses."""
     lst_g = []
     N = len(dict_of_droplets["amp"])  # length of all key are equal
     for i in range(0, N):
         lst_g.append(
             Droplet(amp_val=dict_of_droplets["amp"][i],
                     vit_val=dict_of_droplets["vit"][i]))
     return lst_g
Beispiel #3
0
    def droplet(self):
        self.updateSeed()
        chunk_nums = randChunkNums(self.num_chunks)
        data = None
        for num in chunk_nums:
            if data is None:
                data = self.chunk(num)
            else:
                data = xor(data, self.chunk(num))

        return Droplet(data, self.seed, self.num_chunks)
Beispiel #4
0
 def calib_size(self):
     """ 
     map pixels to mm 
     
     - place object with known size at default distance from camera
     - call this fcn
     - enter size of object
     - fcn calculates scale factor and saves it to droplet object
     """
     # do oneshot eval and extract height from droplet, then calc scale and set in droplet
     res, ok = QInputDialog.getDouble(
         self, "Size of calib element",
         "Please enter the height of the test subject in mm:", 0, 0, 100)
     if not ok or res == 0.0:
         return
     self._oneshot_eval = True
     droplt = Droplet()  # singleton
     self.cam.snapshot()
     droplt.set_scale(res / droplt._height)
     logging.info(f"set image to real scae to {res / droplt._height}")
Beispiel #5
0
 def __init__(self, parent=None):
     super(CameraPreview, self).__init__(parent)
     self.roi_origin = QPoint(0, 0)
     self._pixmap: QPixmap = QPixmap(480, 360)
     self._double_buffer: QImage = None
     self._raw_image: np.ndarray = None
     self._image_size = (1, 1)
     self._image_size_invalid = True
     self._roi_rubber_band = ResizableRubberBand(self)
     self._needle_mask = DynamicNeedleMask(self)
     self._needle_mask.update_mask_signal.connect(self.update_mask)
     self._baseline = Baseline(self)
     self._droplet = Droplet()
     self._mask = None
     logging.debug("initialized camera preview")
Beispiel #6
0
from typing import List

import matplotlib.pyplot as plt

from droplet import Droplet


def calc_drag_coefficient_list(droplet: Droplet, func_name: str,
                               list_Rep: List):
    list_Cd = []
    for Rep in list_Rep:
        droplet.Rep = Rep
        method_to_call = getattr(droplet, func_name)
        list_Cd.append(method_to_call())
    return list_Cd


drop = Droplet()

list_Rep = list(range(1, 51))
list_Cd_SN = calc_drag_coefficient_list(drop, "schiller_and_naumann_1935",
                                        list_Rep)
list_Cd_FM = calc_drag_coefficient_list(drop, "feng_and_michaelides_2001",
                                        list_Rep)

plt.style.use("fivethirtyeight")
fig, ax = plt.subplots()
ax.plot(list_Rep, list_Cd_SN, label="Schiller e Naumman")
ax.plot(list_Rep, list_Cd_FM, label="Feng e Michaelides")
ax.legend()
Beispiel #7
0
light_blue = (50, 200, 250)

gameDisplay = pygame.display.set_mode((width, height))
pygame.display.set_caption(name)

font = pygame.font.SysFont(None, 25)  # setting font for later

FPS = 160
clock = pygame.time.Clock()  # Limiting the FPS here

gameExit = False

drop_number = 10

a = [
    Droplet(width, height, 1, gameDisplay, light_blue, 20)
    for i in range(drop_number)
]

#a = Droplet(width, height, 5, gameDisplay, light_blue)

while not gameExit:
    timer = pygame.time.get_ticks(
    )  # Trandrange(0.1, vel)his will give time in milliseconds
    secondTicker = int(timer / 1000)  # Will return whole seconds only
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            # handle the quit case
            gameExit = True

    gameDisplay.fill(dark_blue)
Beispiel #8
0
 def remove_size_calib(self):
     drplt = Droplet()
     drplt.set_scale(None)
Beispiel #9
0
    def get_droplet(self, droplet_id):

        return Droplet.from_existing(droplet_id, self.authentication_token)
Beispiel #10
0
    def create_droplet(self, name, region="sfo1", size="512mb", image=3448641):

        data = {"name": name, "region": region, "size": size, "image": image}
        return Droplet.create_new(data, self.authentication_token)
Beispiel #11
0
def evaluate_droplet(img,
                     y_base,
                     mask: Tuple[int, int, int, int] = None) -> Droplet:
    """ 
    Analyze an image for a droplet and determine the contact angles

    :param img: the image to be evaluated as np.ndarray
    :param y_base: the y coordinate of the surface the droplet sits on
    :returns: a Droplet() object with all the informations
    """
    drplt = Droplet()
    # crop img from baseline down (contains no useful information)
    crop_img = img[:y_base, :]
    shape = img.shape
    height = shape[0]
    width = shape[1]
    if USE_GPU:
        crop_img = cv2.UMat(crop_img)
    # calculate thrresholds
    thresh_high, thresh_im = cv2.threshold(img, 0, 255,
                                           cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    thresh_low = 0.5 * thresh_high
    # thresh_high = 179
    # thresh_low = 76

    # values only for 8bit images!

    # apply canny filter to image
    # FIXME adjust canny params, detect too much edges
    bw_edges = cv2.Canny(crop_img, thresh_low, thresh_high)

    # block detection of syringe
    if (not mask is None):
        x, y, w, h = mask
        bw_edges[:, x:x + w] = 0
        #img[:, x:x+w] = 0
        masked = True
    else:
        masked = False

    edge = find_contour(bw_edges, masked)

    if USE_GPU:
        # fetch contours from gpu memory
        # cntrs = [cv2.UMat.get(c) for c in contours]
        edge = cv2.UMat.get(edge)
        if DEBUG & DBG_SHOW_CONTOURS:
            # img = cv2.drawContours(img,cntrs,-1,(100,100,255),2)
            img = cv2.drawContours(img, edge, -1, (255, 0, 0), 2)

    # apply ellipse fitting algorithm to droplet
    (x0, y0), (maj_ax, min_ax), phi_deg = cv2.fitEllipse(edge)
    phi = radians(phi_deg)
    a = maj_ax / 2
    b = min_ax / 2

    # diesen fit vllt zum laufen bringen https://scikit-image.org/docs/0.15.x/api/skimage.measure.html
    #points = edge.reshape(-1,2)
    #points[:,[0,1]] = points[:,[1,0]]
    # ell = EllipseModel()
    # if not ell.estimate(points): raise RuntimeError('Couldn\'t fit ellipse')
    # x0, y0, a, b, phi = ell.params
    # maj_ax = 2*a
    # min_ax = 2*b
    # phi_deg = degrees(phi)

    if DEBUG & DBG_DRAW_ELLIPSE:
        img = cv2.ellipse(img, (int(round(x0)), int(round(y0))),
                          (int(round(a)), int(round(b))),
                          int(round(phi * 180 / pi)),
                          0,
                          360, (255, 0, 255),
                          thickness=1,
                          lineType=cv2.LINE_AA)
        #img = cv2.ellipse(img, (int(round(x0)),int(round(y0))), (int(round(a)),int(round(b))), 0, 0, 360, (0,0,255), thickness=1, lineType=cv2.LINE_AA)

    # calculate intersections of ellipse with baseline
    intersection = calc_intersection_line_ellipse((x0, y0, a, b, phi),
                                                  (0, y_base))

    if intersection is None or not isinstance(intersection, list):
        raise ContourError('No valid intersections found')
    x_int_l = min(intersection)
    x_int_r = max(intersection)

    foc_len = sqrt(abs(a**2 - b**2))

    # calc slope and angle of tangent at intersections
    m_t_l = calc_slope_of_ellipse((x0, y0, a, b, phi), x_int_l, y_base)
    m_t_r = calc_slope_of_ellipse((x0, y0, a, b, phi), x_int_r, y_base)

    # calc angle from inclination of tangents
    angle_l = (pi - atan2(m_t_l, 1)) % pi
    angle_r = (atan2(m_t_r, 1) + pi) % pi

    # calc area of droplet
    area = calc_area_of_droplet((x_int_l, x_int_r), (x0, y0, a, b, phi),
                                y_base)

    # calc height of droplet
    drplt_height = calc_height_of_droplet((x0, y0, a, b, phi), y_base)

    # write values to droplet object
    drplt.angle_l = degrees(angle_l)
    drplt.angle_r = degrees(angle_r)
    drplt.maj = maj_ax
    drplt.min = min_ax
    drplt.center = (x0, y0)
    drplt.phi = phi
    drplt.tilt_deg = phi_deg
    drplt.tan_l_m = m_t_l
    drplt.tan_r_m = m_t_r
    drplt.line_l = (x_int_l - y_base / m_t_l, 0,
                    x_int_l + (height - y_base) / m_t_l, height)
    drplt.line_r = (x_int_r - y_base / m_t_r, 0,
                    x_int_r + (height - y_base) / m_t_r, height)
    drplt.int_l = (x_int_l, y_base)
    drplt.int_r = (x_int_r, y_base)
    drplt.foc_pt1 = (x0 + foc_len * cos(phi), y0 + foc_len * sin(phi))
    drplt.foc_pt2 = (x0 - foc_len * cos(phi), y0 - foc_len * sin(phi))
    drplt.base_diam = x_int_r - x_int_l
    drplt.area = area
    drplt.height = drplt_height
    drplt.is_valid = True

    if DEBUG & DBG_DRAW_TAN_ANGLE:
        # painting
        y_int = int(round(y_base))
        img = cv2.line(img, (int(round(x_int_l - (y_int / m_t_l))), 0), (int(
            round(x_int_l + ((height - y_int) / m_t_l))), int(round(height))),
                       (255, 0, 255),
                       thickness=1,
                       lineType=cv2.LINE_AA)
        img = cv2.line(img, (int(round(x_int_r - (y_int / m_t_r))), 0), (int(
            round(x_int_r + ((height - y_int) / m_t_r))), int(round(height))),
                       (255, 0, 255),
                       thickness=1,
                       lineType=cv2.LINE_AA)
        img = cv2.ellipse(img, (int(round(x_int_l)), y_int), (20, 20),
                          0,
                          0,
                          -int(round(angle_l * 180 / pi)), (255, 0, 255),
                          thickness=1,
                          lineType=cv2.LINE_AA)
        img = cv2.ellipse(img, (int(round(x_int_r)), y_int), (20, 20),
                          0,
                          180,
                          180 + int(round(angle_r * 180 / pi)), (255, 0, 255),
                          thickness=1,
                          lineType=cv2.LINE_AA)
        img = cv2.line(img, (0, y_int), (width, y_int), (255, 0, 0),
                       thickness=2,
                       lineType=cv2.LINE_AA)
        img = cv2.putText(img, '<' + str(round(angle_l * 180 / pi, 1)),
                          (5, y_int - 5), cv2.FONT_HERSHEY_COMPLEX, .5,
                          (0, 0, 0))
        img = cv2.putText(img, '<' + str(round(angle_r * 180 / pi, 1)),
                          (width - 80, y_int - 5), cv2.FONT_HERSHEY_COMPLEX,
                          .5, (0, 0, 0))