Fanelli面部检测 - PCL代码与作者的实现

时间:2015-06-11 06:40:24

标签: c++ face-recognition head point-cloud-library

我目前正在使用ASUS Xtion在深度+颜色流中提取面部ROI。 目前,我手动使用OpenNI2抓取帧,而不是使用PCL包装器。

在抓取深度图之后,我分别以cv :: Mat和pcl :: PointCloud格式生成点云,以运行Fanelli的决策森林方法两次,一次使用Fanelli自己提供的实现({{3并且一次使用该方法的PCL版本。

Fanelli的代码执行“正常”,即关于执行时间和检测率。然而,当我将我的pcl :: PointClouds喂给PCL森林时,我几乎没有检测到头部并且执行时间非常慢。

还有其他人已经在这两个实现之间做了比较(相同的方法!)? 我试图找出它们之间的差异,除了数据表示和每个方法附带的现有森林(但是,森林是在同一个数据库上训练的!)。

基本上,我这样做:

 public String uploadFile(String sourceFileUri) {


             fileName = sourceFileUri;
             HttpURLConnection conn = null;
             DataOutputStream dos = null;  
             String lineEnd = "\r\n";
             String twoHyphens = "--";
             String boundary = "*****";
             int bytesRead, bytesAvailable, bufferSize;
             byte[] buffer;
             int maxBufferSize = 1 * 1024; 
             File sourceFile = new File(sourceFileUri); 

             if (!sourceFile.isFile()) {
                  return "";


             }
             else
             {
                  try { 

                        // open a URL connection to the Servlet
                      FileInputStream fileInputStream = new FileInputStream(sourceFile);
                      URL urls = new URL(url_upload);
                      conn = (HttpURLConnection) urls.openConnection(); 
                      conn.setDoInput(true); // Allow Inputs
                      conn.setDoOutput(true); // Allow Outputs
                      conn.setUseCaches(false); // Don't use a Cached Copy
                      conn.setChunkedStreamingMode(1024);

                      conn.setRequestMethod("POST");
                      conn.setRequestProperty("Connection", "Keep-Alive");
                      conn.setRequestProperty("ENCTYPE","multipart/form-data");
                      conn.setRequestProperty("Content-Type","multipart/form-data;boundary=" + boundary);
                      conn.setRequestProperty("fileName", fileName); 

                      String cookie=AppController.getInstance().getPrefManger().getCookie();
                      Log.i("hello","cookie"+cookie);

                      conn.setRequestProperty("Cookie", cookie); 

                      dos = new DataOutputStream(conn.getOutputStream());
                      dos.writeBytes(twoHyphens + boundary + lineEnd); 
                      dos.writeBytes("Content-Disposition: form-data; name=\"albumId\"" + lineEnd); 
                      dos.writeBytes(lineEnd);
                      dos.writeBytes(selectedAlbumId); // mobile_no is String variable
                      dos.writeBytes(lineEnd);

                      dos.writeBytes(twoHyphens + boundary + lineEnd); 
                      dos.writeBytes("Content-Disposition: form-data; name=\"caption\"" + lineEnd); 
                      dos.writeBytes(lineEnd);
                      dos.writeBytes(caption.getText().toString()); // mobile_no is String variable
                      dos.writeBytes(lineEnd);


                      dos.writeBytes(twoHyphens + boundary + lineEnd); 
                      dos.writeBytes("Content-Disposition: form-data; name=files;fileName="
                                                + fileName + "" + lineEnd);

                      dos.writeBytes(lineEnd);

                      // create a buffer of  maximum size
                      bytesAvailable = fileInputStream.available(); 

                      bufferSize = Math.min(bytesAvailable, maxBufferSize);
                      buffer = new byte[bufferSize];

                      // read file and write it into form...
                      bytesRead = fileInputStream.read(buffer, 0, bufferSize);  

                      while (bytesRead > 0) {

                        dos.write(buffer, 0, bufferSize);
                        bytesAvailable = fileInputStream.available();
                        bufferSize = Math.min(bytesAvailable, maxBufferSize);
                        bytesRead = fileInputStream.read(buffer, 0, bufferSize);   

                       }

                      // send multipart form data necesssary after file data...
                      dos.writeBytes(lineEnd);
                      dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

                      // Responses from the server (code and message)
                       serverResponseCode = conn.getResponseCode();
                      String serverResponseMessage = conn.getResponseMessage();

                      Log.i("hello", "HTTP Response is : "
                              + serverResponseMessage + ": " + serverResponseCode);

                      if(serverResponseCode == 200){
                           BufferedReader in=new BufferedReader(new InputStreamReader(conn.getInputStream()));
                           String temp;
                           while((temp=in.readLine())!=null)
                           {
                               Log.i("hello", "response is"+temp);

                           }
                      }    

                      //close the streams //
                      fileInputStream.close();
                      dos.flush();
                      dos.close();

                 } catch (MalformedURLException ex) {

                     ex.printStackTrace();

                     runOnUiThread(new Runnable() {
                         public void run() {
                         }
                     });

                     Log.e("hello", "error: " + ex.getMessage(), ex);  
                 } catch (Exception e) {

                     e.printStackTrace();

                     runOnUiThread(new Runnable() {
                         public void run() {
                         }
                     });
                     Log.e("hello", "Exception : "+ e.getMessage(), e);  
                 }
                 return String.valueOf(serverResponseCode); 

              } // End else block 
            } 

使用processNewFrame方法:

<grab frames with OpenNI2 library>
<call processNewFrame method of a frame processing class>

该帧处理类根据提供的示例代码在其构造函数中初始化CRForestEstimator(类具有指针作为成员)以及pcl :: RFFaceDetectorTrainer(类具有“普通”成员变量)。

0 个答案:

没有答案