Convert pixel coordinate into world coordinate in OpenCv2
<p>My program is for object tracking.
I could object tracking and provide objects x,y with coordinates by moments method.</p>

<p><a href="http://i.stack.imgur.com/aAJgO.png" rel="nofollow">enter image description here</a></p>

<p><a href="http://i.stack.imgur.com/Jjj2L.jpg" rel="nofollow">enter image description here</a></p>

<p><strong><em>I want to convert pixel coordinate into world coordinate in OpenCV2.</em></strong>  I've already got rotation matrix(3*3) and Translation vector(3*1) by camera calibration and I know focal length of my camera.</p>

<p>Now, I defined as follows.</p>

<pre><code> CvMat *rotation = (CvMat*)cvLord("Rotation.xml")
 CvMat *translation = (CvMat*)cvLord("Translation.xml")
</code></pre>

<p>And this is the part of my program.</p>

<pre><code>void trackFilteredObject(Mat threshold,Mat HSV, Mat &amp;Birds_image){

  vector &lt;Fruit&gt; apples;

  Mat temp;
  threshold.copyTo(temp);

  // these two vectors needed for output of findContours
  vector&lt; vector&lt;Point&gt; &gt; contours;
  vector&lt;Vec4i&gt; hierarchy;

  // find contours of filtered image using OpenCv findCountours function
  findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );

  // use moments method to find our filtered object.
    double refArea = 0;
    bool objectFound = false;
    if (hierarchy.size() &gt; 0) {
    int numObjects = hierarchy.size();

    // if number of objects greater than MAX_NUM_OBJECTS, we have a noisy filter.
    if(numObjects&lt;MAX_NUM_OBJECTS){
        for (int index = 0; index &gt;= 0; index = hierarchy[index][0]) {
            Moments moment = moments((cv::Mat)contours[index]);
            double area = moment.m00;

            if(area&gt;MIN_OBJECT_AREA){
                Fruit apple;

                // moments method
                apple.setXPos(moment.m10/area);
                apple.setYPos(moment.m01/area); 
                apples.push_back(apple);

                objectFound = true;

             }else objectFound = false;
        }
        if(objectFound ==true){
            // draw object location on screen
            drawObject(apples,Birds_image);
        }
     }else putText(Birds_image,"TOO MUCH NOISE! ADJUST FILTER",Point(0,50),1,2,Scalar(0,0,255),2);
     }
}
</code></pre>

<p>And drawObject(apples,Birds_image) is this.</p>

<pre><code>void drawObject(vector&lt;Fruit&gt; theFruits,Mat &amp;frame){
  for(int i =0; i&lt;theFruits.size(); i++){
  cv::circle(frame,cv::Point(theFruits.at(i).getXPos(),theFruits.at(i).getYPos()),10,cv::Scalar(0,0,255));
  cv::putText(frame,intToString(theFruits.at(i).getXPos())+ " , " + intToString(theFruits.at(i).getYPos()),cv::Point(theFruits.at(i).getXPos(),theFruits.at(i).getYPos()+20),1,1,Scalar(0,255,0));
  }
}
</code></pre>

<p>And I use these souse file and header file.</p>

<p><strong>Fruit.h</strong></p>

<pre><code>#pragma once
#include &lt;string&gt;
using namespace std;

class Fruit
{
public:
Fruit(void);
~Fruit(void);

int getXPos();
void setXPos(int x);


int getYPos();
void setYPos(int y);

private:

int xPos, yPos;
string type;

};
</code></pre>

<p><strong>Fruit.cpp</strong></p>

<pre><code>#include "Fruit.h"


Fruit::Fruit(void)
{
}


Fruit::~Fruit(void)
{
}

int Fruit::getXPos(){
return Fruit::xPos;
}

void Fruit::setXPos(int x){
Fruit::xPos = x;
xPos = x;
}

int Fruit::getYPos(){
return Fruit::yPos;
}

void Fruit::setYPos(int y){
Fruit::yPos = y;
yPos = y;
}
</code></pre>

<p>Could you give me your splendid ideas.</p>