Ask Your Question
0

Bisect Video Feed - Zed Camera

asked 2016-08-09 13:43:43 -0600

Jordan.Brenner gravatar image

Background: I was given a Zed Camera with the task of using it as a stereo camera. StereoLabs provided a proprietary software which requires CUDA (NVIDIA hardware-dependent software package) to run. I found a few tutorials for making and calibrating a stereo camera (example). I need to reformat the Zed camera's video feed in order to use this method.

Goal: I'm trying to set up my zed camera as a stereo camera. The camera takes images which look like this: (see Fig. 1) Fig. 1 - Initial camera output. and using the below script I separated the static image into two halves: (see Figs 2,3) Fig. 2 - Left. Fig. 3 - Right.

Script:

#!usr/bin/python
import cv2
import numpy as np

# Import image
img = cv2.imread('TestPicture3.jpg')

# split image (indexing)
image_left = img[1:1080, 1:1920]
image_right = img[1:1080, 1920:3840]

# Display left and right images
cv2.namedWindow('Left', cv2.WINDOW_NORMAL)
cv2.resizeWindow('Left', 1920, 1080)
cv2.imshow('Left', image_left)

cv2.namedWindow('Right', cv2.WINDOW_NORMAL)
cv2.resizeWindow('Right', 1920, 1080)
cv2.imshow('Right', image_right)

cv2.waitKey(0)

# export images
cv2.imwrite('TestPic_left.jpg', image_left)
cv2.imwrite('TestPic_right.jpg', image_right)

cv2.destroyAllWindows()

I want to bisect the video feed in order to capture left and right video. Below is the script I've written to attempt the bifurcation, but it hasn't worked. What should I do?

#!usr/bin/python
import cv2
import numpy as np

# script imports Zed camera feed and splits the two feeds into left and right frames

# Capture video on camera device 1
vid = cv2.VideoCapture(1)

# Split video feed on left side
imgLeft = vid.read[1:1080, 1:1920]

# Split video feed on right side
imgRight = vid.read[1:1080, 1920:3840]

while(True):
# Capture frame-by-frame
    ret, frame = vid.read()
# Display the resulting frame
    # left
    cv2.namedWindow('Left', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('Left', 2208, 1242)
    cv2.imshow('Left', imgLeft)
    # right
    cv2.namedWindow('Right', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('Right', 2208, 1242)
    cv2.imshow('Right', imgRight)

# End Process
cv2.waitKey(0)
cv2.destroyAllWindows()

The resulting error is:

Traceback (most recent call last):
  File "Split_VideoCapture_Test.py", line 11, in <module>
    imgLeft = vid.read[1:1080, 1:1920]
TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'

Thank in advance for the assistance.

Cheers, Jordan

edit retag flag offensive close merge delete

Comments

1

unrelated, but please rather print out pattern.png , instead of "drawing something". accurracy really matters here.

berak gravatar imageberak ( 2016-08-09 13:54:16 -0600 )edit

I will when I get the camera running. That was just an attempted quick fix.

Jordan.Brenner gravatar imageJordan.Brenner ( 2016-08-09 13:55:37 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-08-09 14:02:20 -0600

berak gravatar image

updated 2016-08-09 14:10:28 -0600

vid.read() is a function, not a numpy array, so you need (at least) another line:

ret, img =  vid.read() # please check if ret==True. only fools don't.
imgLeft  = img[1:1080, 1:1920]
imgRight = img[1:1080, 1920:3840]
edit flag offensive delete link more

Comments

I included the code you provided as follows: #!usr/bin/python import cv2 import numpy as np

# Capture video on camera device 1
vid = cv2.VideoCapture(1)

while(True):
# Capture frame-by-frame
    img, ret =  vid.read() # please check if ret==True. only fools don't.
    imgLeft  = img[1:1080, 1:1920]
    imgRight = img[1:1080, 1920:3840]
# Display the resulting frame
    # left
    cv2.namedWindow('Left', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('Left', 1920, 1080)
    cv2.imshow('Left', imgLeft)
    # right
    cv2.namedWindow('Right', cv2.WINDOW_NORMAL)
    cv2.resizeWindow('Right', 1920, 1080)
    cv2.imshow('Right', imgRight)

Error Message: imgLeft = img[1:1080, 1:1920] TypeError: 'bool' object has no attribute '__getitem__'

Jordan.Brenner gravatar imageJordan.Brenner ( 2016-08-09 14:16:40 -0600 )edit

Thanks for your help.

Jordan.Brenner gravatar imageJordan.Brenner ( 2016-08-09 14:16:54 -0600 )edit

my bad, -- it's ret, img = vid.read(), not img, ret = .. (got it wrong the 1st time i posted, please look again..)

berak gravatar imageberak ( 2016-08-09 14:29:13 -0600 )edit

Comment (1/2) Is there any reason this shouldn't work?

#!usr/bin/python
import cv2
import numpy as np

# script imports Zed camera feed and splits the two feeds into left and right frames

# Capture video on camera device 1
vid = cv2.VideoCapture(1)

while(True):
# Capture frame-by-frame
    ret, img =  vid.read() # please check if ret==True. only fools don't.
    #print "Check if true: %d" % ret
    imgLeft  = img[1:1242, 1:2208]
    imgRight = img[1:1242, 2208:4416]
# Display the resulting frame
    # left
    #cv2.namedWindow('Left', cv2.WINDOW_NORMAL)
    #cv2.resizeWindow('Left', 1920, 1080)
    cv2.imshow('Left', imgLeft)
    # right
    #cv2.namedWindow('Right', cv2.WINDOW_NORMAL)
    #cv2.resizeWindow('Right', 1920, 1080)
    cv2.imshow('Right', imgRight)

# End Process
cv2.waitKey(0)
cv2.destroyAllWindows()
Jordan.Brenner gravatar imageJordan.Brenner ( 2016-08-09 15:23:23 -0600 )edit

Comment (2/2) It opened up a new window labeled Left with nothing shown (white background). The window doesn't respond. After a few seconds the OS takes over requiring the window to be forced to quit.

When the print statement is un-commented the ret remains true until the script is killed.

Jordan.Brenner gravatar imageJordan.Brenner ( 2016-08-09 15:27:20 -0600 )edit

Hi Jordan, Could you tell me how you managed to solve the window not responding issue? I am trying to do something similar and looking for an answer to figure it out. Please help me.

SVijayan gravatar imageSVijayan ( 2017-12-05 09:27:01 -0600 )edit

^^ indentation problem. the waitKey() needs to be inside the loop.

berak gravatar imageberak ( 2018-09-29 00:58:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-08-09 13:43:43 -0600

Seen: 1,522 times

Last updated: Aug 09 '16