E1101:Module 'cv2' has no 'VideoCapture' member [closed]

asked 2018-06-27 23:26:05 -0600

thelearner gravatar image

updated 2018-06-28 00:21:17 -0600

berak gravatar image

getting this error: I tried to do a facial recognition using Facenet, where in the program, this error shows up:

E1101:Module 'cv2' has no 'VideoCapture' member
E1101:Module 'cv2' has no 'INTER_CUBIC' member
E1101:Module 'cv2' has no 'resize' member
E1101:Module 'cv2' has no 'putText' member
E1101:Module 'cv2' has no 'rectangle' member
E1101:Module 'cv2' has no 'imshow' member

code:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
from scipy import misc
import cv2
import matplotlib.pyplot as plt
import numpy as np
import argparse
import facenet
import detect_face
import os
from os.path import join as pjoin
import sys
import time
import copy
import math
import pickle
from sklearn.svm import SVC
from sklearn.externals import joblib

print('Creating networks and loading parameters')
with tf.Graph().as_default():
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.6)
    sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))
    with sess.as_default():
        pnet, rnet, onet = detect_face.create_mtcnn(sess, './d_npy')

        minsize = 20  # minimum size of face
        threshold = [0.6, 0.7, 0.7]  # three steps's threshold
        factor = 0.709  # scale factor
        margin = 44
        frame_interval = 3
        batch_size = 1000
        image_size = 182
        input_image_size = 160

        HumanNames = os.listdir("./input_dir")
        HumanNames.sort()
        print('Loading feature extraction model')
        modeldir = './pre_model/20170511-185253.pb'
        facenet.load_model(modeldir)

        images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")
        embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")
        phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0")
        embedding_size = embeddings.get_shape()[1]

        classifier_filename = './my_class/my_classifier.pkl'
        classifier_filename_exp = os.path.expanduser(classifier_filename)
        with open(classifier_filename_exp, 'rb') as infile:
            (model, class_names) = pickle.load(infile)
            print('load classifier file-> %s' % classifier_filename_exp)

        video_capture = cv2.VideoCapture('./test.mp4')
        c = 0
        counter = 1
        # #video writer
        fourcc = cv2.VideoWriter_fourcc(*'DIVX')
        out = cv2.VideoWriter('3F_0726.avi', fourcc, fps=14, frameSize=(640,480))

        print('Start Recognition!')
        prevTime = 0
        while True:
            ret, frame = video_capture.read()

            frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5)    #resize frame (optional)

            curTime = time.time()+1    # calc fps
            timeF = frame_interval
            counter += 1
            if (counter % 12 == 0):
                if (c % timeF == 0):
                    find_results = []

                    if frame.ndim == 2:
                        frame = facenet.to_rgb(frame)
                    frame = frame[:, :, 0:3]
                    bounding_boxes, _ = detect_face.detect_face(frame, minsize, pnet, rnet, onet, threshold, factor)
                    nrof_faces = bounding_boxes.shape[0]
                    print('Detected_FaceNum: %d' % nrof_faces)

                    if nrof_faces > 0:
                        det = bounding_boxes[:, 0:4]
                        img_size = np.asarray(frame.shape)[0:2]

                        cropped = []
                        scaled = []
                        scaled_reshape = []
                        bb = np.zeros((nrof_faces,4), dtype=np.int32)

                        for i in range(nrof_faces):
                            emb_array = np.zeros((1, embedding_size))

                            bb[i][0] = det[i][0]
                            bb[i][1] = det[i][1]
                            bb[i][2] = det[i][2]
                            bb[i][3] = det[i][3]

                            # inner exception
                            if bb[i][0] <= 0 or bb[i][1] <= 0 or bb[i][2] >= len(frame[0]) or bb[i][3] >= len(frame):
                                print('face is inner of range!')
                                continue

                            cropped.append(frame[bb[i][1]:bb[i][3], bb[i][0]:bb[i][2], :])
                            cropped[i] = facenet.flip(cropped[i], False)
                            scaled.append(misc.imresize(cropped[i], (image_size, image_size), interp='bilinear'))
                            scaled[i] = cv2.resize(scaled[i], (input_image_size ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-05 01:01:22.385668

Comments

which opencv version is it, and how did you install that ?

it looks like a problem related to pylint, so also: how do you run that ? (if there's some IDE, it might be misconfigured)

could you add your code to the question ?

berak gravatar imageberak ( 2018-06-27 23:34:38 -0600 )edit

(base) C:\Windows\system32>pip freeze | grep opencv opencv-python==3.4.1.15

I installed using pip install opencv-python

thelearner gravatar imagethelearner ( 2018-06-28 00:05:51 -0600 )edit

that should usually work without any problem.

but again, your code, please.

berak gravatar imageberak ( 2018-06-28 00:09:42 -0600 )edit

length of the chars not supportive.

thelearner gravatar imagethelearner ( 2018-06-28 00:10:23 -0600 )edit

please move the code into your question (where it can be properly formatted)

berak gravatar imageberak ( 2018-06-28 00:11:26 -0600 )edit
1

Moved the code

thelearner gravatar imagethelearner ( 2018-06-28 00:14:55 -0600 )edit

there are no obvious errors there, and i'm sure, it will run fine on a simple cmdline.

it's not really an opencv problem, you must have misconfigured your IDE / editor. (which, btw, is ?)

berak gravatar imageberak ( 2018-06-28 00:26:29 -0600 )edit

i am running it on the Terminal, No IDE, Terminal says the same error, debugged in IDE, find out the problem.

thelearner gravatar imagethelearner ( 2018-06-28 00:28:58 -0600 )edit

i am running it on the Terminal

how do you get pylint errors, then ? it's a mystery to me.

berak gravatar imageberak ( 2018-06-30 02:30:56 -0600 )edit