Ask Your Question
0

Why are my two other frames completely black?

asked 2017-02-03 23:56:15 -0600

 import cv2
import argparse
import datetime
import time
import numpy as np

cap = cv2.VideoCapture('test.mp4')

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

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    high_gray = np.array([88,62,35])
    low_gray = np.array([149,122,99])

    mask = cv2.inRange(gray, low_gray, high_gray)

    res = cv2.bitwise_and(frame, frame, mask=mask)




    cv2.imshow('frame', gray)
    cv2.imshow('mask', mask)
    cv2.imshow('res', res)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()

cv2.destroyAllWindows()

The frame window shows the video but the other two are completely black

edit retag flag offensive close merge delete

Comments

There is something wrong

supra56 gravatar imagesupra56 ( 2017-12-03 20:40:04 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-12-04 05:21:46 -0600

supra56 gravatar image

updated 2017-12-04 05:24:00 -0600

The problem has been solved. Play around with low_gray values and leave constant high_gray 155. And the max always be 255. You can play around with low_gray but don't set too high than 200.

import cv2
import argparse
import datetime
import time
import numpy as np

cap = cv2.VideoCapture('test.mp4')

while(cap.isOpened()):
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    high_gray = np.array([150,255,255])
    low_gray = np.array([20,50,199])
    mask = cv2.inRange(gray, low_gray, high_gray)
    res = cv2.bitwise_and(frame, frame, mask=mask)

    cv2.imshow('frame', gray)
    cv2.imshow('mask', mask)
    cv2.imshow('res', res)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
edit flag offensive delete link more
0

answered 2017-02-04 01:13:34 -0600

berak gravatar image

if your mask is all black, the bitwise_and operation will result in an all black frame, too (no pixels were retained).

try to "open up" your upper/lower range values for inRange() , currently, a very "red" or very "bright" image won't survive your filter.

edit flag offensive delete link more

Comments

berak, the upper will x, 255, 255 While lower can changed x,x,x The max will be up to 200

supra56 gravatar imagesupra56 ( 2017-12-04 05:26:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-03 23:46:51 -0600

Seen: 546 times

Last updated: Dec 04 '17