繁体   English   中英

FastCV拐角检测样本-了解fcvMemAlloc输入

[英]FastCV corner detection sample - understanding fcvMemAlloc input

我目前正在尝试了解FastCV软件包中提供的示例之一。 有一个函数执行内存分配fcvMemAlloc() ,该函数将字节数和字节对齐作为输入。 在名为FastCVSample.cpp的示例中,必须将内存分配给大小为wxh的数据块,但是,在分配内存时, 它们会将总数除以2 我不明白为什么? 如果有人有线索,我会很高兴听到他的消息:-)

这是函数调用-请参见下面对fcvMemAlloc()的调用

JNIEXPORT void 
JNICALL Java_com_qualcomm_fastcorner_FastCVSample_update
(
JNIEnv*     env, 
jobject     obj, 
jbyteArray  img, 
jint        w, 
jint        h
)
{ 
   jbyte*            jimgData = NULL;
   jboolean          isCopy = 0;
   uint32_t*         curCornerPtr = 0;
   uint8_t*          renderBuffer;
   uint64_t          time;
   float             timeMs;

   // Get data from JNI 
   jimgData = env->GetByteArrayElements( img, &isCopy );

   renderBuffer = getRenderBuffer( w, h );  

   lockRenderBuffer();

   time = getTimeMicroSeconds();

  // jimgData might not be 128 bit aligned.
  // fcvColorYUV420toRGB565u8() and other fcv functionality inside 
  // updateCorners() require 128 bit memory aligned. In case of jimgData 
  // is not 128 bit aligned, it will allocate memory that is 128 bit 
  // aligned and copies jimgData to the aligned memory.

  uint8_t*  pJimgData = (uint8_t*)jimgData;    

  // Check if camera image data is not aligned.
  if( (uintptr_t)jimgData & 0xF )
  {
     // Allow for rescale if dimensions changed.
     if( w != (int)state.alignedImgWidth || 
         h != (int)state.alignedImgHeight )
     {
        if( state.alignedImgBuf != NULL )
        {
           DPRINTF( "%s %d Creating aligned for preview\n", 
              __FILE__, __LINE__ );
           fcvMemFree( state.alignedImgBuf );
           state.alignedImgBuf = NULL;
        }
     }

     // Allocate buffer for aligned data if necessary.
     if( state.alignedImgBuf == NULL )
     { 
        state.alignedImgWidth = w;
        state.alignedImgHeight = h;
        state.alignedImgBuf = (uint8_t*)fcvMemAlloc( w*h*3/2, 16 ); <-----Why   this and not fcvMemAlloc( w*h*3, 16 )
     }

     memcpy( state.alignedImgBuf, jimgData, w*h*3/2 );    <---- same here  
     pJimgData = state.alignedImgBuf;
  }

  // Copy the image first in our own buffer to avoid corruption during 
  // rendering. Not that we can still have corruption in image while we do 
  // copy but we can't help that. 

  // if viewfinder is disabled, simply set to gray
  if( state.disableVF )
  {
     // Loop through RGB565 values and set to gray.
     uint32_t size = getRenderBufferSize();
     for( uint32_t i=0; i<size; i+=2 )
     {
        renderBuffer[i] = 0x10;
        renderBuffer[i+1] = 0x84;
     }
  }
  else
  {
     fcvColorYUV420toRGB565u8(
        pJimgData,
        w,
        h, 
        (uint32_t*)renderBuffer );
  }

  // Perform FastCV Corner processing
  updateCorners( (uint8_t*)pJimgData, w, h );

  timeMs = ( getTimeMicroSeconds() - time ) / 1000.f;
  state.timeFilteredMs = 
     ((state.timeFilteredMs*(29.f/30.f)) + (float)(timeMs/30.f));

  // RGB Color conversion
  if( !state.enableOverlayPixels )
  {
     state.numCorners  = 0;
  }

  // Have renderer draw corners on render buffer.
  drawCorners( state.corners, state.numCorners );

  unlockRenderBuffer();

  // Let JNI know we don't need data anymore. this is important!
 env->ReleaseByteArrayElements( img, jimgData, JNI_ABORT );
}

我在以下站点找到了答案: 如何使用OpenGLES 2.0在libgdx中的背景上实时渲染Android的YUV-NV21摄像机图像? 他在那里解释说YUV帧的格式是(wxhx 3)/2 ,这就是为什么要分配特定数量的内存的原因。

注意:这里还有另一个示例: http : //www.codeproject.com/Tips/691062/Resizing-NV-image-using-Nearest-Neighbor-Interpo

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM