Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract_vgg16_features does not work with variable frame rate #7

Open
qysnn opened this issue Nov 14, 2018 · 0 comments
Open

extract_vgg16_features does not work with variable frame rate #7

qysnn opened this issue Nov 14, 2018 · 0 comments

Comments

@qysnn
Copy link

qysnn commented Nov 14, 2018

I am trying to apply this code to a custom dataset and find out that it will hang at vgg16_feature_extractor.py line 44 forever. After doing some search, I think the problem is that cv2.CAP_PROP_POS_MSEC does not work with variable frame rate. So I changed the code to:

def extract_vgg16_features(model, video_input_file_path, feature_output_file_path):
    if os.path.exists(feature_output_file_path):
        return np.load(feature_output_file_path)
    count = 0
    print('Extracting frames from video: ', video_input_file_path)
    vidcap = cv2.VideoCapture(video_input_file_path)
    fps=int(vidcap.get(cv2.CAP_PROP_FPS))
    success, image = vidcap.read()
    features = []
    success = True
    while success:
        success, image = vidcap.read()
        count = count + 1
        # print('Read a new frame: ', success)
        if success and count%fps==0:
            img = cv2.resize(image, (224, 224), interpolation=cv2.INTER_AREA)
            input = img_to_array(img)
            input = np.expand_dims(input, axis=0)
            input = preprocess_input(input)
            feature = model.predict(input).ravel()
            features.append(feature)
            
    unscaled_features = np.array(features)
    np.save(feature_output_file_path, unscaled_features)
    return unscaled_features

And it seems this code is working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant