sourishg / stereo-calibration

:camera: :camera: Stereo camera calibration using OpenCV and C++
http://sourishghosh.com/2016/stereo-calibration-cpp-opencv/
619 stars 239 forks source link

How to use kinect v2 with this code? #22

Open 1gen100 opened 5 years ago

1gen100 commented 5 years ago

I'm trying to use this code with kinect v2 by take one image from one camera and then from the other so i changede the C++ code read_images.cpp to only take from one soruce. But when I run the code it turns on my webcam, even thoug I have activated kinect using iai_kinect repository.

Can you help?

sourishg commented 5 years ago

@1gen100 this might help: https://docs.opencv.org/master/d7/d6f/tutorial_kinect_openni.html

You may need to change the argument passed to the VideoCapture constructor for getting the Kinect feed.

1gen100 commented 5 years ago

Hey @sourishg,

Thanks I have tried this but with no succes, I think it's because it uses OPENNI that works for Kinect V1, but not for Kinect V2.

1gen100 commented 4 years ago

I didn't have time to wait so I made this code, but it's not that good and effective. Could you help me with this?

#!/usr/bin/python

import roslib
import rospy
import** cv2
import sys
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import numpy as np

class PositionTracker:

def __init__(self):
    # subscribe to kinect image messages
    self.sub = rospy.Subscriber("kinect2/hd/image_color", Image, self.image_callback, queue_size=1)
    self.bridge = CvBridge()

def image_callback(self,data):
    try:
        cv_image = self.bridge.imgmsg_to_cv2(data)
    except CvBridgeError as e:
        print(e)

    cv_image=cv2.resize(cv_image,(640,360))

    cv2.imshow("Image window", cv_image)
    c=cv2.waitKey(10)
    #print(c)
    click=0
    if c ==108:
        print("Insert left image num:")
        click= input()
        print("Saving img pair", click)
        filename1 = "%sleft%d.%s" % ("../c-camera/", click, "jpg")
        cv2.imwrite(filename1, cv_image)
    if c ==114:
        print("Insert right image num:")
        click= input()
        print("Saving img pair", click)
        filename1 = "%sright%d.%s" % ("../c-camera/", click, "jpg")
        cv2.imwrite(filename1, cv_image)
        #time.sleep(3)

def main(args):
    ic = PositionTracker()
    rospy.init_node('kinect_tracker')
    try:
        rospy.spin()
    except KeyboardInterrupt:
        print("Shutting down")
    cv2.destroyAllWindows()

if __name__ == '__main__':
    main(sys.argv)