Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use kinect v2 with this code? #22

Open
1gen100 opened this issue Oct 30, 2019 · 3 comments
Open

How to use kinect v2 with this code? #22

1gen100 opened this issue Oct 30, 2019 · 3 comments

Comments

@1gen100
Copy link

1gen100 commented Oct 30, 2019

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
Copy link
Owner

@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
Copy link
Author

1gen100 commented Nov 6, 2019

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
Copy link
Author

1gen100 commented Nov 20, 2019

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants