Ejemplo n.º 1
0
def count_objects(top, bottom, right, left, crop_img, roi_position, y_min,
                  y_max, deviation):
    direction = "n.a."  # means not available, it is just initialization
    isInROI = True  # is the object that is inside Region Of Interest
    update_csv = False

    if (abs(((bottom + top) / 2) - roi_position) < deviation):
        is_vehicle_detected.insert(0, 1)
        update_csv = True
        image_saver.save_image(crop_img)  # save detected object image
        print("Passei pela condição de centro do box na rotina OBJECT_COUNTER")
    else:
        if (abs(((right + left) / 2) - roi_position)) >= deviation and (abs((
            (right + left) / 2) - roi_position)) <= deviation + .5:
            print("OBJECT COUTNER Distancia do centro do box",
                  (abs(((right + left) / 2) - roi_position)), "Botton:",
                  bottom, "bottom referencia:",
                  bottom_position_of_detected_vehicle[0])

    if (bottom > bottom_position_of_detected_vehicle[0]):
        direction = "down"
    else:
        direction = "up"

    bottom_position_of_detected_vehicle.insert(0, (bottom))

    return direction, is_vehicle_detected, update_csv
Ejemplo n.º 2
0
def predict_speed(
    top,
    bottom,
    right,
    left,
    current_frame_number,
    crop_img,
    roi_position,
):
    speed = 0  # means not available, it is just initialization
    direction = 'n.a.'  # means not available, it is just initialization
    scale_constant = 1  # manual scaling because we did not performed camera calibration
    isInROI = True  # is the object that is inside Region Of Interest
    update_csv = False

    if bottom < 100:
        scale_constant = 1  # scale_constant is used for manual scaling because we did not performed camera calibration
    elif bottom > 100 and bottom < 400:
        scale_constant = 2  # scale_constant is used for manual scaling because we did not performed camera calibration
    else:
        isInROI = False

    if len(bottom_position_of_detected_vehicle) != 0 and bottom \
            - bottom_position_of_detected_vehicle[0] > 0 and 170 \
            < bottom_position_of_detected_vehicle[0] \
            and bottom_position_of_detected_vehicle[0] < 520 \
            and roi_position < bottom:
        # print('contrue')
        is_vehicle_detected.insert(0, 1)
        update_csv = True
        image_saver.save_image(crop_img)  # save detected vehicle image

    # for debugging
    # print("bottom_position_of_detected_vehicle[0]: " + str(bottom_position_of_detected_vehicle[0]))
    # print("bottom: " + str(bottom))
    if bottom > bottom_position_of_detected_vehicle[0]:
        direction = 'down'
    else:
        direction = 'up'

    if isInROI:

        pixel_length = bottom - bottom_position_of_detected_vehicle[0]
        #################################################################################################################
        # We will change this scale to detect near accurate speed, it should probably be more than 44 and there should be a correcting factor for drone speed effect.

        scale_real_length = (
            pixel_length * 44
        )  # multiplied by 44 to convert pixel length to real length in meters (chenge 44 to get length in meters for your case)
        total_time_passed = current_frame_number - current_frame_number_list[0]
        scale_real_time_passed = total_time_passed * 24  # get the elapsed total time for a vehicle to pass through ROI area (24 = fps)
        print(scale_real_time_passed)
        if scale_real_time_passed != 0:
            speed = scale_real_length / scale_real_time_passed / scale_constant  # performing manual scaling because we have not performed camera calibration
            speed = speed / 6 * 40  # use reference constant to get vehicle speed prediction in kilometer unit
            current_frame_number_list.insert(0, current_frame_number)
            bottom_position_of_detected_vehicle.insert(0, bottom)

    return (direction, speed, is_vehicle_detected, update_csv)
Ejemplo n.º 3
0
def predict_speed(
    top,
    bottom,
    right,
    left,
    current_frame_number,
    crop_img,
    roi_position,
    ):
    speed = 'n.a.'  # means not available, it is just initialization
    direction = 'n.a.'  # means not available, it is just initialization
    scale_constant = 1  # manual scaling because we did not performed camera calibration
    isInROI = True  # is the object that is inside Region Of Interest
    update_csv = False
    print('entered')
    
    if bottom < 250:
        scale_constant = 1  # scale_constant is used for manual scaling because we did not performed camera calibration
    elif bottom > 250 and bottom < 320:
        scale_constant = 2  # scale_constant is used for manual scaling because we did not performed camera calibration
    else:
        isInROI = False
    print(len(bottom_position_of_detected_vehicle))
    print('position of Detected_vehicle=', bottom_position_of_detected_vehicle[0])

    if len(bottom_position_of_detected_vehicle) != 0 and bottom \
        - bottom_position_of_detected_vehicle[0] > 0 and 160 \
        < bottom_position_of_detected_vehicle[0] \
        and bottom_position_of_detected_vehicle[0] < 310 \
        and roi_position < bottom: #Initially 205->160 and 210->310
        is_vehicle_detected.insert(0, 1)
        update_csv = True
        image_saver.save_image(crop_img)  # save detected vehicle image
        import time
        time.sleep(1)

    # for debugging
    # print("bottom_position_of_detected_vehicle[0]: " + str(bottom_position_of_detected_vehicle[0]))
    # print("bottom: " + str(bottom))
    if bottom > bottom_position_of_detected_vehicle[0]:
        direction = 'down'
    else:
        direction = 'up'

    if isInROI:
        pixel_length = bottom - bottom_position_of_detected_vehicle[0]
        scale_real_length = pixel_length * 44  # multiplied by 44 to convert pixel length to real length in meters (chenge 44 to get length in meters for your case)
        total_time_passed = current_frame_number - current_frame_number_list[0]
        scale_real_time_passed = total_time_passed * 24  # get the elapsed total time for a vehicle to pass through ROI area (24 = fps)
        if scale_real_time_passed != 0:
            speed = scale_real_length / scale_real_time_passed / scale_constant  # performing manual scaling because we have not performed camera calibration
            speed = speed / 6 * 40  # use reference constant to get vehicle speed prediction in kilometer unit
            current_frame_number_list.insert(0, current_frame_number)
            bottom_position_of_detected_vehicle.insert(0, bottom)

    return (direction, speed, is_vehicle_detected, update_csv)
Ejemplo n.º 4
0
def predict_speed(
    top,
    bottom,
    right,
    left,
    current_frame_number,
    crop_img,
    roi_position,
):
    speed = 'n.a.'  # Significa no disponible, es solo inicialización.
    direction = 'n.a.'  # Significa no disponible, es solo inicialización.
    scale_constant = 1  # Escala manual porque no realizamos la calibración de la cámara.
    isInROI = True  #Es el objeto que se encuentra dentro de Región de Interés.
    update_csv = False

    if bottom < 250:
        scale_constant = 1  # scale_constant se usa para la escala manual porque no realizamos la calibración de la cámara
    elif bottom > 250 and bottom < 320:
        scale_constant = 2  # scale_constant se usa para la escala manual porque no realizamos la calibración de la cámara
    else:
        isInROI = False

    if len(bottom_position_of_detected_vehicle) != 0 and bottom \
        - bottom_position_of_detected_vehicle[0] > 0 and 205 \
        < bottom_position_of_detected_vehicle[0] \
        and bottom_position_of_detected_vehicle[0] < 210 \
        and roi_position < bottom:
        is_vehicle_detected.insert(0, 1)
        update_csv = True
        image_saver.save_image(
            crop_img)  # guardar la imagen del vhiculo detectado

    if bottom > bottom_position_of_detected_vehicle[0]:
        direction = 'Abajo'
    else:
        direction = 'Arriba'

    if isInROI:
        pixel_length = bottom - bottom_position_of_detected_vehicle[0]
        scale_real_length = pixel_length * 44  # multiplicado por 44 para convertir la longitud del píxel en longitud real en metros (chenge 44 para obtener la longitud en metros para su caso)
        total_time_passed = current_frame_number - current_frame_number_list[0]
        scale_real_time_passed = total_time_passed * 24  # obtener el tiempo total transcurrido para que un vehículo pase por el área de ROI (24 = fps)
        if scale_real_time_passed != 0:
            speed = scale_real_length / scale_real_time_passed / scale_constant  # Realización de escala manual porque no hemos realizado calibración de cámara.
            speed = speed / 6 * 40  # use la constante de referencia para obtener la predicción de la velocidad del vehículo en unidades de kilómetro
            current_frame_number_list.insert(0, current_frame_number)
            bottom_position_of_detected_vehicle.insert(0, bottom)

    return (direction, speed, is_vehicle_detected, update_csv)
def predict_speed(top, bottom, right, left, current_frame_number, crop_img,
                  roi_position):
    speed = "n.a."  # means not available, it is just initialization
    direction = "n.a."  # means not available, it is just initialization
    scale_constant = 1  # manual scaling because we did not performed camera calibration
    isInROI = True  # is the object that is inside Region Of Interest
    update_csv = False

    if ((bottom) < 250):
        scale_constant = 1  # scale_constant is used for manual scaling because we did not performed camera calibration
    elif ((bottom > 250) and (bottom < 320)):
        scale_constant = 2  # scale_constant is used for manual scaling because we did not performed camera calibration
    else:
        isInROI = False

    if ((len(bottom_position_of_detected_vehicle) != 0)
            and bottom - bottom_position_of_detected_vehicle[0] > 0
            and 205 < bottom_position_of_detected_vehicle[0]
            and bottom_position_of_detected_vehicle[0] < 210
            and roi_position < bottom):
        is_vehicle_detected.insert(0, 1)
        update_csv = True
        image_saver.save_image(crop_img)  # save detected vehicle image

    # for debugging
    # print("bottom_position_of_detected_vehicle[0]: " + str(bottom_position_of_detected_vehicle[0]))
    # print("bottom: " + str(bottom))

    if (bottom > bottom_position_of_detected_vehicle[0]):
        direction = "down"
    else:
        direction = "up"

    if (isInROI):
        pixel_length = ((bottom)) - bottom_position_of_detected_vehicle[0]
        scale_real_length = pixel_length * 44  # multiplied by 44 to convert pixel length to real length in meters (chenge 44 to get length in meters for your case)
        total_time_passed = (current_frame_number -
                             current_frame_number_list[0])
        scale_real_time_passed = total_time_passed * 24  # get the elapsed total time for a vehicle to pass through ROI area (24 = fps)
        if (scale_real_time_passed != 0):
            speed = (
                scale_real_length / scale_real_time_passed
            ) / scale_constant  # performing manual scaling because we have not performed camera calibration
            speed = speed / 6 * 40  # use reference constant to get vehicle speed prediction in kilometer unit
            current_frame_number_list.insert(0, current_frame_number)
            bottom_position_of_detected_vehicle.insert(0, (bottom))

    return direction, speed, is_vehicle_detected, update_csv
Ejemplo n.º 6
0
def count_objects_x_axis(top, bottom, right, left, crop_img, roi_position, y_min, y_max, deviation):   
        direction = "n.a." # means not available, it is just initialization
        isInROI = True # is the object that is inside Region Of Interest
        update_csv = False
        if (abs(((right+left)/2)-roi_position) < deviation):
          is_vehicle_detected.insert(0,1)
          update_csv = True
          image_saver.save_image(crop_img) # save detected object image

        if(bottom > bottom_position_of_detected_vehicle[0]):
                direction = "down"
        else:
                direction = "up"

        bottom_position_of_detected_vehicle.insert(0,(bottom))

        return direction, is_vehicle_detected, update_csv
Ejemplo n.º 7
0
def count_objects(r, name1,top, bottom, right, left, crop_img, roi_position, y_min, y_max, deviation):   
        #print(current_frame_number)
        direction = "n.a." # means not available, it is just initialization
        speed = 0
        isInROI = True # is the object that is inside Region Of Interest
        update_csv = False
        #print(width)

        if (r==crop_img):
          update_csv = True
          is_vehicle_detected.insert(0,2)
          print("Detection.............")
          print(name1)
          veh.insert(0,name1)
          #update_csv = True
          #print(crop_img)
          print("##################")
          image_saver.save_image(crop_img) # save detected object image
        return (direction, speed, is_vehicle_detected, update_csv, veh)
Ejemplo n.º 8
0
def count_objects_x_axis(top, bottom, right, left, crop_img, roi_position, y_min, y_max, deviation,roiArea):   
        direction = "n.a." # means not available, it is just initialization
        isInROI = True # is the object that is inside Region Of Interest
        update_csv = False

        if (abs(((right+left)/2)-roi_position) < deviation and last_frame_is_vehicle_detected[0] !=1 ):
          is_vehicle_detected.insert(0,1)
          #Added for testing
          last_frame_is_vehicle_detected.insert(0,1)
          update_csv = True
          image_saver.save_image(crop_img) # save detected object image
        else:
                last_frame_is_vehicle_detected.insert(0,0)
                  

        if(left > left_position_of_detected_vehicle[0]):
                direction = "right"
        else:
                direction = "left"
        # This to keep track of last frame detection
        bottom_position_of_detected_vehicle.insert(0,(bottom))
        left_position_of_detected_vehicle.insert(0,(left))

        return direction, is_vehicle_detected, update_csv