Os algoritmos não detectam corretamente

Home Fóruns Fórum Rastreamento de Objetos com Python e OpenCV Os algoritmos não detectam corretamente

Visualizando 2 posts - 1 até 2 (de 2 do total)
  • Autor
    Posts
  • #43541

    Olá

    estou fazendo o curso atualmente  e seguindo os passo a passo, quando executo o código os algoritmos (nenhum) detectam corretamente os corredores, segue o código:

     

    # ——————- instalação de pacotes ——————- #
    # pip install opencv-python==4.9.0
    # pip install opencv-contrib-python==3.4.10.37 4.9.0
    # ————————————————————- #

    # importar pacotes #
    import cv2
    import sys
    from random import randint

    # Versão Opencv #
    (major_ver, minor_ver, subminor_ver) = (cv2.__version__).split(‘.’)
    print(cv2.__version__
    )
    # Tipos de rastreamentos #
    tracker_types = [‘BOOSTING’,
    ‘MIL’,
    ‘KCF’,
    ‘TLD’,
    ‘MEDIANFLOW’,
    ‘MOSSE’,
    ‘CSRT’]

    tracker_type = tracker_types[3]

    # Selecionador do tipo de rastreamento #
    if int(minor_ver) < 3 :
    tracker = tracker_type
    else:
    if tracker_type == ‘BOOSTING’:
    tracker = cv2.legacy.TrackerBoosting_create()
    if tracker_type == ‘MIL’:
    tracker = cv2.legacy.TrackerMIL_create()
    if tracker_type == ‘KCF’:
    tracker = cv2.legacy.TrackerKCF_create()
    if tracker_type == ‘TLD’:
    tracker = cv2.legacy.TrackerTLD_create()
    if tracker_type == ‘MEDIANFLOW’:
    tracker = cv2.legacy.TrackerMedianFlow_create()
    if tracker_type == ‘MOSSE’:
    tracker = cv2.legacy.TrackerMOSSE_create()
    if tracker_type == ‘CSRT’:
    tracker = cv2.legacy.TrackerCSRT_create()

    # Carregar o video #
    video = cv2.VideoCapture(‘Videos/race.mp4’)
    # Verificar se o video esta disponivel #
    if not video.isOpened():
    print(‘Não foi possivel encontrar o vídeo’)
    sys.exit()

    # Ler os frames dos videos #
    ok, frame = video.read()
    # Verifica se o vídeo não está corrompido #
    if not ok:
    print(‘Não foi possivel ler o arquivo do video’)
    sys.exit()

    # Seleciona a região de interesse
    bbox = cv2.selectROI(frame, False)
    #print(bbox)

    #Inicializa o tracker
    ok = tracker.init(frame, bbox)
    #print(ok)

    # Random de cores para o bbox
    colors = (randint(0,255), randint(0, 255), randint(0, 255))
    #print(colors)

    while True:
    ok, frame = video.read()
    if not ok:
    break

    timer = cv2.getTickCount()
    ok, bbox = tracker.update(frame)
    #print(ok, bbox)

    fps = cv2.getTickFrequency() / (cv2.getTickCount() – timer)

    if ok:
    (x, y, w, h) = {int(v) for v in bbox}
    cv2.rectangle(frame,(x,y),(x + w, y + h), colors, 2, 1)
    else:
    cv2.putText(frame, ‘Falha no rastreamento’, (100, 80),
    cv2.FONT_HERSHEY_COMPLEX, .75, (0,0,255),2)

    cv2.putText(frame, tracker_type + ‘-Tracker’, (100, 50),
    cv2.FONT_HERSHEY_SIMPLEX, .75, (50,170,50), 2)

    cv2.putText(frame, ‘FPS-‘ + str(int(fps)), (100, 80),
    cv2.FONT_HERSHEY_SIMPLEX, .75, (50,170,50), 2)

    cv2.imshow(‘Tracking’, frame)
    if cv2.waitKey(1) & 0XFF == 27: # ESC
    break

     

    #43542
    Dalton Vargas
    Moderador

      Olá Mateus,

       

      Consegui identificar o problema.

      É na condição onde você está comparando a versão do OpenCV para instanciar o rastreador, é necessário comparar a variável major_ver e minor_ver na condição conforme segue abaixo:

      #Ajustar disso

      if int(minor_ver) < 3 :
      tracker = tracker_type

      # Para isso

      if int(major_ver) == 3 and int(minor_ver) < 3:
      tracker = cv2.Tracker_create(tracker_type.upper())

      • Esta resposta foi modificada 1 ano, 3 meses atrás por Dalton Vargas.
    Visualizando 2 posts - 1 até 2 (de 2 do total)
    • Você deve fazer login para responder a este tópico.