darknet预测分类动态库:采集转换为darknet格式

采集中的数据存储:

 for (int j = 0; j < nHeight; j++)		
 {
    for (int i = 0; i < nWidth; i++)			
	{    		    	
		buff[j*nWidth + i] = pOCTData[j * nRealWidth + i];
     }
 }	

需要做的转换:

for (int i = 0; i < m_wid; ++i)
		{
			for (int j = 0; j < m_height; ++j)
			{
				if (isSimulate)
				{
					num++;
					m_tmpImgData[i][j] = num;
				}
				else
				{
					m_tmpImgData[i][j] = (int)(pOctdata->_pbyOCTDataBuffer[i * m_height + j]);
				}

			}
		}


		for (int i = 0; i < m_height; ++i)
		{
			for (int j = 0; j < m_wid; ++j)
			{
				int iPos = j * c;
				int k = i * m_wid * c + iPos;
				if (c == 3)
				{
					mImgData[h][k] = (unsigned char)m_tmpImgData[j][m_height - i - 1];
					mImgData[h][k + 1] = (unsigned char)m_tmpImgData[j][m_height - i - 1];
					mImgData[h][k + 2] = (unsigned char)m_tmpImgData[j][m_height - i - 1];
				} 
				else
				{
					mImgData[h][k] = (unsigned char)m_tmpImgData[j][m_height - i - 1];
				}
				
			}

		}

将上面采集转darknet存储格式代码,两个循环合并成一个循环:

for (int i = 0; i < m_height; ++i)
{
	for (int j = 0; j < m_wid; ++j)
		{
			int iPos = j * c;
			int k = i * m_wid * c + iPos;
			if (c == 3)
			{
					
				mImgData[h][k] = (unsigned char)pOctdata->_pbyOCTDataBuffer[j * m_height + m_height - i - 1];
				mImgData[h][k + 1] = (unsigned char)pOctdata->_pbyOCTDataBuffer[j * m_height + m_height - i - 1];
				mImgData[h][k + 2] = (unsigned char)pOctdata->_pbyOCTDataBuffer[j * m_height + m_height - i - 1];
			} 
			else
			{
				mImgData[h][k] = (unsigned char)m_tmpImgData[j][m_height - i - 1];
			}
				
		}

}

将上面的代码GPU加速:

__global__ void MatChannelsOneToThree(unsigned char* dst,unsigned char* src,int w,int h,int c)
{
    int i = blockIdx.x * blockDim.x + threadIdx.x; 
    int j = blockIdx.y * blockDim.y + threadIdx.y; 
	int k = blockIdx.z * blockDim.z + threadIdx.z;
    if (i

 

你可能感兴趣的:(高性能计算HPC,#,darknet,darknet,CUDA)