I am creating an image processing using npp. (CUDA 11.4)
In the process, I ran into a problem.
The problem is that the labeling function npiCompressedMarkerLabelsUFInfo returns different results each time, even though it is processing the same image.
Specifically, the function returns npicompressedMarkerLabelsInfo, and although the nMarkerLabelPixelCount is the same each time, the oMarkerLabelBoundingBox is slightly different each time. This is a problem.
The code and output in problem is as follows
//// test image
int testwidth = 256;
int testheight = 256;
cv::Mat test = cv::Mat::zeros(cv::Size(testwidth,testheight), CV_8UC1);
cv::Vec<uchar,1> *src;
src = test.ptr<cv::Vec<uchar,1>>(2);
src[2] = 255;
src[3] = 255;
cudaMemcpyAsync(cudaMem_u8_A, test.data, test.rows * test.step,cudaMemcpyHostToDevice, nppStreamCtx.hStream);
//// LabelMarker
Npp8u *buffer;
int hpBufferSize;
nppiLabelMarkersUFGetBufferSize_32u_C1R({256, 256}, &hpBufferSize);
cudaMallocAsync((void**)&buffer, hpBufferSize, stream);
nppiLabelMarkersUF_8u32u_C1R_Ctx(cudaMem_u8_A, 256*sizeof(Npp8u), cudaMem_u32_A, 256*sizeof(Npp32u), {256,256}, nppiNormInf, buffer, nppStreamCtx);
cudaFreeAsync(buffer, stream);
//// Compress Marker
nppiCompressMarkerLabelsGetBufferSize_32u_C1R(256*256, &hpBufferSize);
cudaMallocAsync((void**)&buffer, hpBufferSize, stream);
int nCompressedLabelCount;
nppiCompressMarkerLabelsUF_32u_C1IR_Ctx(cudaMem_u32_A, 256*sizeof(Npp32u), {256,256}, 256*256, &nCompressedLabelCount, buffer, nppStreamCtx);
cudaFreeAsync(buffer, stream);
//// Get LabelMarker Info
unsigned int nInfoListSize;
nppiCompressedMarkerLabelsUFGetInfoListSize_32u_C1R(nCompressedLabelCount, &nInfoListSize);
NppiCompressedMarkerLabelsInfo *pMarkerLabelsInfoList, *pMarkerLabelsInfoListHost;
cudaMallocAsync((void**)&pMarkerLabelsInfoList, nInfoListSize,stream);
cudaMallocHost((void**)&pMarkerLabelsInfoListHost, nInfoListSize);
nppiCompressedMarkerLabelsUFInfo_32u_C1R_Ctx(cudaMem_u32_A, 256*sizeof(Npp32u), {256,256}, nCompressedLabelCount, pMarkerLabelsInfoList,
NULL,0,NULL,0,NULL,NULL,NULL,NULL,nppStreamCtx);
cudaMemcpyAsync(pMarkerLabelsInfoListHost,pMarkerLabelsInfoList,nInfoListSize,cudaMemcpyDeviceToHost, nppStreamCtx.hStream);
cudaStreamSynchronize(nppStreamCtx.hStream);
for (unsigned int l = 0; l <= nCompressedLabelCount; l++){
printf(" Rect # %2d : PixelCount: %6d @ BoundingBox.x %4d, y %4d, width %4d, height %4d\n",
l,
pMarkerLabelsInfoListHost[l].nMarkerLabelPixelCount,
pMarkerLabelsInfoListHost[l].oMarkerLabelBoundingBox.x,
pMarkerLabelsInfoListHost[l].oMarkerLabelBoundingBox.y,
pMarkerLabelsInfoListHost[l].oMarkerLabelBoundingBox.width,
pMarkerLabelsInfoListHost[l].oMarkerLabelBoundingBox.height);
}
cudaFreeAsync(pMarkerLabelsInfoList, stream);
cudaFreeHost(pMarkerLabelsInfoListHost);
The output is as follows You can see that the bounding value changes each time.
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 11, width 255, height 255
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 2, width 255, height 255
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 2, width 255, height 255
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 19, width 255, height 254
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 1, width 255, height 255
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 0, width 255, height 253
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 0, width 255, height 255
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 0, width 255, height 255
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 2, width 255, height 255
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
Rect # 0 : PixelCount: 65534 @ BoundingBox.x 0, y 0, width 255, height 248
Rect # 1 : PixelCount: 2 @ BoundingBox.x 5, y 4, width 0, height 0
I would appreciate if you could tell me the cause of the problem and what to do about it.