2016-12-08 47 views
0

ウェブカメラまたはビデオから顔のランドマークポイントをインポートしようとしていますファイルに検出された顔のランドマークを保存する

dlibをファイルに使用しています。 Iは、端末

上で検出されたすべてのランドマークを表示することができるが、それは唯一

出力ファイルに第一及び第二のランドマークponits(x、y)を保存し、そして

にすべての検出されたランドマークを保存していません出力ファイル

#include <dlib/opencv.h> 
#include <opencv2/highgui/highgui.hpp> 
#include <dlib/image_processing/frontal_face_detector.h> 
#include <dlib/image_processing/render_face_detections.h> 
#include <dlib/image_processing.h> 
#include <dlib/gui_widgets.h> 

using namespace dlib; 
using namespace std; 

int main() 
{ 
try 
{ 
    cv::VideoCapture cap(0); 
    if (!cap.isOpened()) 
    { 
     cerr << "Unable to connect to camera" << endl; 
     return 1; 
    } 

    image_window win; 

    frontal_face_detector detector = get_frontal_face_detector(); 
    shape_predictor pose_model; 
    deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model; 


    while(!win.is_closed()) 
    { 
     // Grab a frame 
     cv::Mat temp; 
     cap >> temp; 


     cv_image<bgr_pixel> cimg(temp); 


     std::vector<rectangle> faces = detector(cimg); 

     std::vector<full_object_detection> shapes; 
     for (unsigned long i = 0; i < faces.size(); ++i) 
     { 

       full_object_detection shape = pose_model(cimg, faces[i]); 

     cout << "number of parts: "<< shape.num_parts() << endl; 
      cout << "pixel position of first part: " << shape.part(0) << endl; 
    cout << "pixel position of second part: " << shape.part(1) << endl; 
    shapes.push_back(pose_model(cimg, faces[i])); 


    const full_object_detection& d = shapes[0]; 
      ofstream outputfile; 
      outputfile.open("data1.txt"); 


       outputfile<< shape.part(0).x() << " " << shape.part(0).y() << endl; 
       outputfile<< shape.part(1).x() << " " << shape.part(1).y() << endl; 


       } 

     win.clear_overlay(); 
     win.set_image(cimg); 
     win.add_overlay(render_face_detections(shapes)); 
    } 
} 
catch(serialization_error& e) 
{ 
    cout << "You need dlib's default face landmarking model file to run this example." << endl; 
    cout << "You can get it from the following URL: " << endl; 
    cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl; 
    cout << endl << e.what() << endl; 
} 
catch(exception& e) 
{ 
    cout << e.what() << endl; 
} 

}

答えて

0

私が間違っているか、あなたが唯一持っているときにすべてのランドマークを保存したい:
ofstream outputfile; outputfile.open("data1.txt"); outputfile<< shape.part(0).x() << " " << shape.part(0).y() << endl; outputfile<< shape.part(1).x() << " " << shape.part(1).y() << endl;
ファイルを正しく閉じることさえできません。 forステートメントで試してください。

+0

ランドマーク(例えば0〜10)を列挙したときにshape.part(0).x()とshape.part(0).y()を使用した場合、検出された最初のランドマークと2番目のランドマークのみが保存されます。 ofstreamの出力ファイル。すでにループの中にあります – tofi

+0

'FILE'のような出力ファイルに対して他のタイプを試しましたか? –

+0

私はちょうど.csv出力を試みましたが、最初の2つの値 – tofi

関連する問題