updated
authorVadim Pisarevsky <no@email>
Mon, 14 Jun 2010 12:21:57 +0000 (12:21 +0000)
committerVadim Pisarevsky <no@email>
Mon, 14 Jun 2010 12:21:57 +0000 (12:21 +0000)
samples/cpp/build3dmodel.cpp
samples/cpp/select3dobj.cpp

index 5b27a64..4310511 100644 (file)
@@ -270,7 +270,7 @@ static Point3f triangulatePoint(const vector<Point2f>& ps,
 {
     Mat_<double> K(cameraMatrix);
     
-    if( ps.size() > 2 )
+    /*if( ps.size() > 2 )
     {
         Mat_<double> L(ps.size()*3, 4), U, evalues;
         Mat_<double> P(3,4), Rt(3,4), Rt_part1=Rt.colRange(0,3), Rt_part2=Rt.colRange(3,4);
@@ -296,7 +296,7 @@ static Point3f triangulatePoint(const vector<Point2f>& ps,
         double W = fabs(U(3,3)) > FLT_EPSILON ? 1./U(3,3) : 0;
         return Point3f((float)(U(3,0)*W), (float)(U(3,1)*W), (float)(U(3,2)*W));
     }
-    else
+    else*/
     {
         Mat_<float> iK = K.inv();
         Mat_<float> R1t = Mat_<float>(Rs[0]).t();
@@ -497,18 +497,10 @@ static void build3dmodel( const Ptr<FeatureDetector>& detector,
                 
                 double e1 = norm(imgpts1[0] - keypoints1[i1].pt);
                 double e2 = norm(imgpts2[0] - keypoints2[i2].pt);
-                if( e1 + e2 > 10 )
+                if( e1 + e2 > 5 )
                     continue;
                 
                 pairsFound++;
-                //pts_k[0] = imgpts1[0];
-                //pts_k[1] = imgpts2[0];
-                //objpt = triangulatePoint(pts_k, Rs_k, ts_k, cameraMatrix);
-                //objpts[0] = objpt;
-                //projectPoints(Mat(objpts), Rs_k[0], ts_k[0], cameraMatrix, Mat(), imgpts1);
-                //projectPoints(Mat(objpts), Rs_k[1], ts_k[1], cameraMatrix, Mat(), imgpts2);
-                //double e1 = norm(imgpts1[0] - keypoints1[i1].pt);
-                //double e2 = norm(imgpts2[0] - keypoints2[i2].pt);
                 
                 //model.points.push_back(objpt);   
                 pairs[Pair2i(i1+dstart[i], i2+dstart[j])] = 1;
index 38fb1d0..83cbe4b 100644 (file)
@@ -67,7 +67,7 @@ static Point3f image2plane(Point2f imgpt, const Mat& R, const Mat& tvec,
 
 static Rect extract3DBox(const Mat& frame, Mat& shownFrame, Mat& selectedObjFrame, 
                          const Mat& cameraMatrix, const Mat& rvec, const Mat& tvec,
-                         const vector<Point3f>& box, int nobjpt)
+                         const vector<Point3f>& box, int nobjpt, bool runExtraSegmentation)
 {
     selectedObjFrame = Mat::zeros(frame.size(), frame.type());
     if( nobjpt == 0 )
@@ -120,8 +120,13 @@ static Rect extract3DBox(const Mat& frame, Mat& shownFrame, Mat& selectedObjFram
     convexHull(Mat_<Point>(Mat(imgpt)), hull);
     Mat selectedObjMask = Mat::zeros(frame.size(), CV_8U);
     fillConvexPoly(selectedObjMask, &hull[0], hull.size(), Scalar::all(255), 8, 0);
+    Rect roi = boundingRect(Mat(hull)) & Rect(Point(), frame.size());
+    
+    ///////////////// insert GrabCut here ////////////////////
+    //////////////////////////////////////////////////////////
+    
     frame.copyTo(selectedObjFrame, selectedObjMask);
-    return boundingRect(Mat(hull)) & Rect(Point(), frame.size());
+    return roi;
 }
 
 
@@ -211,7 +216,7 @@ static int select3DBox(const string& windowname, const string& selWinName, const
         
         frame.copyTo(shownFrame);
         extract3DBox(frame, shownFrame, selectedObjFrame,
-                     cameraMatrix, rvec, tvec, box, npt);
+                     cameraMatrix, rvec, tvec, box, npt, false);
         imshow(windowname, shownFrame);
         imshow(selWinName, selectedObjFrame);
         
@@ -500,7 +505,7 @@ int main(int argc, char** argv)
             if( !box.empty() )
             {
                 Rect r = extract3DBox(frame, shownFrame, selectedObjFrame,
-                                      cameraMatrix, rvec, tvec, box, 4);
+                                      cameraMatrix, rvec, tvec, box, 4, true);
                 if( r.area() )
                 {
                     const int maxFrameIdx = 10000;