../../CamelliaLib/html/test_labeling.cpp
1| #include <iostream.h>
2| #include <stdlib.h>
3| #include "camellia.h"
4|
5| extern "C" int sortfunc(const void *a, const void *b)
6| {
7| CamBlobInfo *ba=(CamBlobInfo*)a;
8| CamBlobInfo *bb=(CamBlobInfo*)b;
9| return bb->surface-ba->surface;
10| }
11|
12| void cpp_example_labeling()
13| {
14| CamImage image,yuv;
15|
16|
17| image.load_bmp("resources/alfa156.bmp");
18| image.to_yuv(yuv);
19|
20|
21| CamROI roi(3,0,0,yuv.width,yuv.height);
22| yuv.set_roi(roi);
23|
24|
25| CamRLEImage thr;
26| yuv.encode_threshold(thr,150);
27|
28|
29| CamBlobs blobs;
30| thr.labeling(blobs);
31|
32|
33| std::cout<<blobs.nbBlobs<<" blobs detected"<<std::endl;
34|
35|
36| for (int i=0;i<blobs.nbBlobs;i++) {
37| image.draw_rectangle(blobs[i].left, blobs[i].top,
38| blobs[i].left+blobs[i].width-1, blobs[i].top+blobs[i].height-1,
39| CAM_RGB(255,0,0));
40| }
41| image.save_bmp("output/alfa156_labeling.bmp");
42|
43|
44| qsort((void*)blobs.blobInfo,blobs.nbBlobs,sizeof(CamBlobInfo),sortfunc);
45| std::cout<<"The bigger blob is at position ("<<blobs[0].cx<<","<<blobs[0].cy<<") and its surface is "<<blobs[0].surface<<" pixels"<<std::endl;
46| }