Ask Your Question

Jordan.Brenner's profile - activity

2019-08-16 09:25:02 -0600 received badge  Notable Question (source)
2018-04-10 09:48:50 -0600 received badge  Popular Question (source)
2016-08-19 15:55:00 -0600 commented answer Display a rectified video (stereo camera)

From here you can write the video to a file and then upload it.

2016-08-19 15:53:58 -0600 answered a question Display a rectified video (stereo camera)

The function Undistort can be used to display the rectification. Try something like this:

# Left camera
dst1=cv2.undistort(vidL,cameraMatrixLeft,distCoeffsLeft) # apply calibration to left camera
cv2.namedWindow('Left Calibrated',cv2.WINDOW_NORMAL) # resizeable window
cv2.imshow('Left Calibrated',dst1) # display left image
# Right camera
dst2=cv2.undistort(vidR,cameraMatrixRight,distCoeffsRight) # apply calibration to right camera
cv2.namedWindow('Right Calibrated',cv2.WINDOW_NORMAL) # resizeable window
cv2.imshow('Right Calibrated',dst2) # display right image

Cheers, Jordan

2016-08-19 15:26:23 -0600 asked a question What is the cv2.stereoCalibrate: "imageSize" variable format? [Python]

What is the cv2.stereoCalibrate: "imageSize" variable format?

I've tried numpy arrays, defining the variable plainly, pixel count (720 x 1280 x 3), etc. but I'm still getting the below error. I can't seem to find any documentation on it. Please help!

Snippet of code:

# Stereo calibration
imageSize = (720,1280)
retval_stereo,cameraMatrixLeft,distCoeffsLeft,cameraMatrixRight,distCoeffsRight,R,T,E,F=cv2.stereoCalibrate(
    objPoints,
    imgPoints1,
    imgPoints2,
    cameraMatrix1,
    distCoeffs1,
    cameraMatrix2,
    distCoeffs2,
    imageSize
    )

Error message:

Traceback (most recent call last):
  File "CalibrationOpenCV_TEST.py", line 78, in <module>
    imageSize
SystemError: new style getargs format but argument is not a tuple
2016-08-19 09:14:25 -0600 received badge  Enthusiast
2016-08-15 14:56:43 -0600 received badge  Editor (source)
2016-08-15 13:47:20 -0600 asked a question Stereo Camera Calibration/Rectification with Zed Camera (python)

Goal: I want to calibrate and rectify my Zed camera. The input video feed leads to some complications. However, this method produces fewer headaches than buying a new computer which contains an NVIDIA GPU just for the sake of using the proprietary software (which may or may not allow of the end goal). For now, all I want to do is calibrate my camera so I can start estimating sizes and distances of (first known, then unknown) objects.

For reference, this is what the Zed camera's video looks like: Zed camera, raw image

FIG. 1 - Raw image from Zed Camera.

I figured out a quick-and-dirty method of splitting the video feed. Generally:

cap = cv2.VideoCapture(1) # video sourced from Zed camera

while(True):
# Capture frame-by-frame
    ret, frame = cap.read()
# partition video
    vidL = frame[0:1080, 0:1280] # left camera
    vidR = frame[0:1080, 1281:2560] # right camera

The resulting images look like this: Zed camera, left image

FIG 2. - Left image from Zed camera.

Zed camera, right image

FIG 3. - Right image from Zed Camera.

My code is adapted from this source . It runs a calibration and rectification of a camera with live video feed. I tested it before I made any changes and it worked, albeit with some odd results. (It partially rectified a section of the image.)

#!usr/bin/python

import cv, cv2, time, sys
import numpy as np

#n_boards=0 #no of boards
#board_w=int(sys.argv[1])   # number of horizontal corners
#board_h=int(sys.argv[2])   # number of vertical corners
#n_boards=int(sys.argv[3])
#board_n=board_w*board_h        # no of total corners
#board_sz=(board_w,board_h) #size of board

n_boards=0  #no of boards
board_w=(9) # number of horizontal corners
board_h=(6) # number of vertical corners
n_boards=1
board_n=board_w*board_h     # no of total corners
board_sz=(board_w,board_h)  #size of board

#   creation of memory storages
    # Left
image_pointsL=cv.CreateMat(n_boards*board_n,2,cv.CV_32FC1)
object_pointsL=cv.CreateMat(n_boards*board_n,3,cv.CV_32FC1)
point_countsL=cv.CreateMat(n_boards,1,cv.CV_32SC1)
intrinsic_matrixL=cv.CreateMat(3,3,cv.CV_32FC1)
distortion_coefficient_L=cv.CreateMat(5,1,cv.CV_32FC1)
    # Right
image_pointsR=cv.CreateMat(n_boards*board_n,2,cv.CV_32FC1)
object_pointsR=cv.CreateMat(n_boards*board_n,3,cv.CV_32FC1)
point_countsR=cv.CreateMat(n_boards,1,cv.CV_32SC1)
intrinsic_matrixR=cv.CreateMat(3,3,cv.CV_32FC1)
distortion_coefficient_R=cv.CreateMat(5,1,cv.CV_32FC1)

#   capture frames of specified properties and modification of matrix values
i=0
y=0
z=0     # to print number of frames
successes=0
# Capture video from camera
capture = cv2.VideoCapture(1) # 1 references Zed camera, cange as necessary
# partition video


while(successes<n_boards):
    found=0
    ret, frame = capture.read()
    capL = frame[0:1080, 0:1280] # left camera
    capR = frame[0:1080, 1281:2560] # right camera
    imageL = cv2.cv.iplimage(capL)
    imageR = cv2.cv.iplimage(capR)

    # Left
    gray_imageL=cv.CreateImage(cv.GetSize(imageL),8,1)
    cv.CvtColor(imageL,gray_imageL,cv.CV_BGR2GRAY)
    # Right
    gray_imageR=cv.CreateImage(cv.GetSize(imageR),8,1)
    cv.CvtColor(imageR,gray_imageR,cv.CV_BGR2GRAY)

    # Left
    (foundL,cornersL)=cv.FindChessboardCorners(gray_imageL,board_sz,cv.CV_CALIB_CB_ADAPTIVE_THRESH| cv.CV_CALIB_CB_FILTER_QUADS)
    cornersL=cv.FindCornerSubPix(gray_imageL,cornersL,(11,11),(-1,-1),(cv.CV_TERMCRIT_EPS ...
(more)
2016-08-15 13:05:37 -0600 received badge  Supporter (source)
2016-08-15 13:05:36 -0600 received badge  Scholar (source)
2016-08-09 15:27:20 -0600 commented answer Bisect Video Feed - Zed Camera

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.

2016-08-09 15:23:23 -0600 commented answer Bisect Video Feed - Zed Camera

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()
2016-08-09 14:16:54 -0600 commented answer Bisect Video Feed - Zed Camera

Thanks for your help.

2016-08-09 14:16:40 -0600 commented answer Bisect Video Feed - Zed Camera

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__'

2016-08-09 13:55:37 -0600 commented question Bisect Video Feed - Zed Camera

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

2016-08-09 13:48:03 -0600 asked a question Bisect Video Feed - Zed Camera

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