I didn't really read the details of your question very closely, nor did I look at the link. It seems to me that there are so many different conventions and coordinate systems used for camera geometry it often leads to confusion. If you are using a camera calibrated with camera_calibration, and the camera information is available as a CameraInfo topic, then I'd recommend using the image_geometry package. The two packages are specifically designed to work together, and the image_geometry
package contains a number of useful functions. Check out the Python API and the C++ API.
Originally posted by jarvisschultz with karma: 9031 on 2016-06-17
This answer was ACCEPTED on the original site
Post score: 1
Original comments
Comment by laurent on 2016-06-20:
I tried using image_geometry, but i get a 'NoneType' object has no attribute 'getitem' error when using it. Here's what i did
self.img_geo = PinholeCameraModel()
(r_x,r_y,r_z) = self.img_geo.projectPixelTo3dRay((359,28))
any idea whats going on?
Comment by laurent on 2016-06-20:
I obviously imported the packages beforehand
Comment by jarvisschultz on 2016-06-20:
You need to read in the camera calibration parameters
cam_info = rospy.wait_for_message("/camera1/camera_info", CameraInfo, timeout=None)
img_proc = PinholeCameraModel()
img_proc.fromCameraInfo(cam_info)
n = img_proc.projectPixelTo3dRay((30,30))
Comment by laurent on 2016-06-20:
So I added that bit to my code, but it seems that the code stops at rospy.wait_for_message and doesnt compute the rest
Comment by laurent on 2016-06-20:
So I figrued that that cam_info was basically just subscribing to a camera, so i replcaed the wait_for_message with directly subscribing to the camera. and the error that i get says that 'Subscriber' object has no attribute 'K'
Comment by jarvisschultz on 2016-06-20:
Your first comment indicates, most likely, that you weren't publishing a CameraInfo message on the /camera1/camera_info
topic. Your second comment indicates that you are passing the created subscriber into the fromCameraInfo
method. That is not correct.
Comment by jarvisschultz on 2016-06-20:
The wait_for_message
function creates a subscriber, waits until the topic is published, and returns a copy of the message that was received. My code doesn't return a subscriber, it returns a CameraInfo message that has been filled out with information from camera calibration.
Comment by laurent on 2016-06-20:
So given that I revert back to wait_for_message
, how do i publish a CameraInfo message? You can't publish to the camera right, you can only subscribe to it
Comment by jarvisschultz on 2016-06-20:
Most camera drivers provide functionality to automatically publish this topic based on a calibrated camera yaml file. You should also be able to manually publish this from the command line using rostopic pub.
Comment by laurent on 2016-06-20:
It turns out i was wrongly entering my topic. I managed to get it to work, thank you so much, your help has been immensely useul
Comment by jarvisschultz on 2016-06-20:
Glad to hear it! Please close your other question, or provide an answer describing how you solved the problem. http://answers.ros.org/question/237563/subscriber-object-has-no-attribute-k-image_geometry-python-ros/
Comment by laurent on 2016-06-20:
I have a quick question. Now that i have that unit vector passing through the center point of my camera, how do i convert that into real 3d coordinates?
Comment by jarvisschultz on 2016-06-21:
AFAIK you can't do this without another piece of information. E.g. if you know how far away the object is, you can correctly scale the x,y components. Or, if you have vectors pointing to multiple keypoints on an object with known size and orientation.
Comment by jarvisschultz on 2016-06-21:
Tag tracking systems and checkerboard calibrators get pose estimation by knowing that the black/white corners are all on the same plane and either knowing how big the marker/checkerboard is, or being able to extract that info somehow.