2017-12-12 1 views
0

나는 현재 어떤 작업을 수행 할 tensorflow를 사용하여 프레임을 가로 프레임에 데이터를 작성하고이를 다시 주입하는 것 Gstreamer1.0 플러그인을 쓰고 있어요에서 입력 텐서를 작성tensorflow - gstreamer를 버퍼

I를. C/C++에서이 작업을 수행하고 있으며 데이터가 Gstreamer와 Tensorflow간에 흐르지 않으면 문제가 발생합니다.

데이터를 추출하고 입력 Tensor를 구성해야하는 GstBuffer 객체에 프레임이 있습니다. 형식은 항상 동일한 UINT8 RGB 매트릭스이다 폭, 높이, 3] 바이트 포인터와

/* extract raw data from gstreamer buffer */ 
gpointer bytes; 
gst_buffer_extract_dup(outbuf, 0, size, &bytes, &copied); 

내가 지금 구성해야합니다 :

Tensor input(tensorflow::DT_UINT8, tensorflow::TensorShape(cwidth, cheight, 3)); 

나는 내가 생각하고 아무 생각이 어떻게 하기 위해서.
나는 gpointer 및 tensorflow에서 어떻게 작동하는지에 대한 정보 나 예제를 찾을 수 없었습니다. 필자의 경우가 아닌 소스로 파일을 사용하는 예제를 찾을 수있었습니다.

모든 리드 또는 통찰력은 크게 감사하겠습니다.

답변

0

길을 찾았지만 버퍼가 RGB, 3 채널 프레임 버퍼 일 때만 작동합니다.

Tensor ConvertRGBBufferToInputTensor(gpointer buffer, gint cwidth, gint cheight, gint channel) { 

    Tensor input_tensor(tensorflow::DT_UINT8, tensorflow::TensorShape({1, cwidth, cheight, channel})); 
    auto input_tensor_mapped = input_tensor.tensor<uint8_t, 4>(); 

    uint8_t * uintdata = (uint8_t*)buffer; 

    for (int y = 0; y < cheight; ++y) { 
     const uint8_t* source_row = uintdata + (y * cwidth * channel); 
     for (int x = 0; x < cwidth; ++x) { 
      const uint8_t* source_pixel = source_row + (x * channel); 
      for (int c = 0; c < channel; ++c) { 
       const uint8_t* source_value = source_pixel + c; 
       input_tensor_mapped(0, y, x, c) = *source_value; 
      } 
     } 
    } 

    return input_tensor; 
} 

그리고 당신이 GstBuffer

/* extract raw data from the buffer and convert it to an input tensor */ 
gst_buffer_extract_dup(outbuf, 0, size, &bytes, &copied); 
GST_INFO("Extracted %" G_GSIZE_FORMAT " from buffer" , copied); 
Tensor input_tensor = ConvertRGBBufferToInputTensor(bytes, cwidth, cheight); 
g_free(bytes); 
이있을 때있는 GStreamer에서 그것을 사용하는