Skip to content

AttributeError: partially initialized module 'cv2' has no attribute 'VideoCapture' #303

@emanuelsc3s

Description

@emanuelsc3s

I have the error when running:

used Delphi 10.4.2 and Python 3.9.2 64bit

Traceback (most recent call last):
File "", line 51, in remover_frame_a_frame_e_fazer_predicoes_e_plotar
AttributeError: partially initialized module 'cv2' has no attribute 'VideoCapture' (most likely due to a circular import)

Help please...

def retirar_frame_a_frame_e_fazer_predicoes_e_plotar(path_video, y_true):

  violent_count = 0
  non_violent_count = 0
  contador = 0
  
  vetor_probs = []
  vetor_labels = []
  vetor_imagens = []
  
  cap = cv2.VideoCapture(path_video)

  while (cap.isOpened()):
    ret, frame = cap.read()

    if (ret == False):
      break
    
    img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 

    img_pil = Image.fromarray(img)
    vetor_imagens.append(img_pil)

    img_tensor = transformer(img_pil)
    
    img_tensor.unsqueeze_(0)

    resultado = model.forward(img_tensor)

    probs = torch.exp(resultado)

    probs = probs.max(1)

    probabilidade = probs[0].detach().numpy()[0]
    vetor_probs.append(probabilidade)

    label_predita = probs[1].detach().numpy()[0]
    vetor_labels.append(label_predita)

    contador += 1

    if (label_predita == 1):
      violent_count += 1
    else:
      non_violent_count += 1
    
    taxa_frames_violentos = 100*violent_count/contador
    taxa_frames_nao_violentos = 100*non_violent_count/contador
  
  plt.figure(figsize=(15, 10))
  for k in range(9):
    plt.subplot(3, 3, k+1)
    n = random.randint(0, len(vetor_probs)-1)
    img = vetor_imagens[n]
    label = vetor_labels[n]
    plt.imshow(img)
    plt.xticks([])
    plt.yticks([])
    plt.title('Real: {0}\nPredito: {1}'.format(vetor_classes[y_true], vetor_classes[label]))
  
  plt.show()

  return np.array(vetor_probs), np.array(vetor_labels), taxa_frames_violentos, taxa_frames_nao_violentos

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions