Jump to content

OpenCV video processing with SRWorks


Recommended Posts

HI everyone!

I'm working with HTC Vive Pro Eye, and i need to extract flow of images from each cameras and conìvert it level of gray.

In OpenCV when i need to extract flow of images from laptop's web camera, I use the  following code : 

import cv2 as cv

cap = cv.VideoCapture(0)

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

    gray_video = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)             
    cv.imshow("Frame", gray_video)

    if cv.waitKey(1) & 0xFF == ord("e"):
        break

cap.release()
cv.destroyAllWindows()

Is it possible to call, both HTC VIVE Pro Eye cameras? I mean, at the second row of the code at cv.Video.Capture(0) it is possible to acquire video from webcamera. Is it possible to call both cameras?

 

Thank you kindly

 

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

Seems like the other view is available if you set the correct frame size (reference post).

Here is how you can do it (note that the 2nd view is available below the 1st one).
 

import argparse
import cv2 as cv

def get_args():
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("--cam", type=int, default=0, help="camera index")
    args = parser.parse_args()
    return args

def play_video(idx):
    cap = cv.VideoCapture(idx)
    width = cap.get(cv.CAP_PROP_FRAME_WIDTH)
    height = cap.get(cv.CAP_PROP_FRAME_HEIGHT)
    print(f"default size: {width} x {height}")
    cap.set(cv.CAP_PROP_FRAME_WIDTH, width)
    cap.set(cv.CAP_PROP_FRAME_HEIGHT, height*2)
    if not cap.isOpened():
        print("Cannot open camera")
        exit()
    print(f"Showing camera {idx} with backend {cap.getBackendName()}")
    cv.namedWindow("Vive Pro Front cameras: Left=Bottom, Right=Top")
    while True:
        # Capture frame-by-frame
        ret, frame = cap.read()
        # if frame is read correctly ret is True
        if not ret:
            print("Can't receive frame (stream end?). Exiting ...")
            break
        # Our operations on the frame come here
        # Display the resulting frame
        cv.imshow("Vive Pro Front cameras: Left=Bottom, Right=Top", frame)
        k = cv.waitKey(1)
        if k == ord('q') or k == 27:
            break
    # When everything done, release the capture
    cap.release()
    cv.destroyAllWindows()


if __name__=="__main__":
    args = get_args()
    play_video(args.cam)

 

left_right_default.thumb.png.2efd29da6e69cc275ee66f92bf373802.png


 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...