Gets the number of black objects in a binary image.
#include "l_bitmap.h"
L_LTIMGCOR_API L_INT EXT_FUNCTION L_ObjectCounter(pBitmap, uCount, pCallback, pUserData, uFlags)
Pointer to the bitmap handle referencing the binary image.
Pointer to a variable to be updated with the number of black objects.
Optional callback function for additional processing.
If you do not provide a callback function, use NULL as the value of this parameter.
If you do provide a callback function, use the function pointer as the value of this parameter.
The callback function must adhere to the function prototype described in OBJECTCOUNTERCALLBACK function.
Void pointer that you can use to pass one or more additional parameters that the callback function needs.
To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.
If the additional parameters are not needed, you can pass NULL in this parameter.
Reserved for future use. Must be 0.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
If white objects are on a black image, the colors in the specified bitmap must be inverted by calling L_InvertBitmap function.
This function only works on 1-bit images.
This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.
Win32, x64, Linux.
This example loads a bitmap and counts the objects in it and prints the parameters of the rectangle surrounding the region .
L_INT EXT_CALLBACK ObjectCounterExampleCB(L_RECT rect, L_INT** pObject, L_VOID* pUserData)
{
UNREFERENCED_PARAMETER(pUserData);
UNREFERENCED_PARAMETER(pObject);
L_TCHAR szMsg[200];
wsprintf(szMsg, TEXT("Region Bounds: left=%d, right=%d, top=%d, bottom=%d\n"), rect.left, rect.right, rect.top, rect.bottom);
_tprintf(_T("%s"), szMsg);
return SUCCESS;
}
L_INT ObjectCounterExample(L_VOID)
{
L_INT nRet;
BITMAPHANDLE LeadBitmap; /*Bitmap handle to hold the loaded image*/
L_UINT uCount; /*variable to hold the count*/
/* Load the bitmap, keeping the bits per pixel of the file */
nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("clean.tif")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
if (nRet != SUCCESS)
return nRet;
if (LeadBitmap.BitsPerPixel != 1)
return ERROR_BITPERPIXEL;
//Apply Object Counter
nRet = L_ObjectCounter(&LeadBitmap, &uCount, ObjectCounterExampleCB, NULL, 0);
if (nRet != SUCCESS)
return nRet;
//free bitmap
if (LeadBitmap.Flags.Allocated)
L_FreeBitmap(&LeadBitmap);
return SUCCESS;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document