/* CFLoadFromDIB loads image from Windows DIB */ CF_ERROR __EXPORT_TYPE CFLoadFromDIB( CF_IMAGE hImage, CF_BMP info, BYTE* DIBPixels ) { CF_ERROR status = CF_SUCCESS; TLFImage* image = (TLFImage*)hImage; if(image == NULL) { status = CFF_INVALID_HANDLE; return status; } awpImage* img = NULL; BITMAPINFO lInfo; memcpy( &lInfo, &info, sizeof(CF_BMP) ); if( awpDIBToImage(&lInfo, DIBPixels, &img)!= AWP_OK ) { status = CFF_INVALID_DIB; return status; } try { image->SetImage( img ); } catch (...) { status = CFCR_NOT_ENOUGH_MEMORY; awpReleaseImage(&img); return status; } awpReleaseImage(&img); return status; }
bool TLFSabotage::PorocessImage(awpImage* img, bool* result) { *result = false; if (img == NULL) return false; // преобразования. awpImage* tmp = NULL; // копируем входное изображение во временное. if (awpCopyImage(img, &tmp) != AWP_OK) return false; if (tmp->sSizeX != this->m_srcWidth || tmp->sSizeY != this->m_srcHeight || tmp->bChannels != this->m_srcBPP) { // переинициализация TLFImage initImage; initImage.SetImage(img); this->Init(&initImage); _AWP_SAFE_RELEASE_(tmp) return true; }
// загрузака растрового изображения из неструктуированной памяти. CF_ERROR __EXPORT_TYPE CFLoadFromDump(CF_IMAGE hImage, CF_WORD width, CF_WORD height, CF_WORD bpp, CF_BYTE* pixels, CF_WORD line_width) { CF_ERROR status = CF_SUCCESS; // получение указателя на изображение TLFImage* image = (TLFImage*)hImage; if(image == NULL) { status = CFF_INVALID_HANDLE; return status; } // проверка указателя на пиксели if (pixels == NULL) { status = CFF_INVALID_PARAM; return status; } // проверка числа битов на пиксель if (bpp != 8 && bpp != 24) { status = CFF_INVALID_PARAM; return status; } awpImage* tmp = NULL; if (awpCreateImage(&tmp, width, height, bpp == 8?1:3, AWP_BYTE) != AWP_OK) { status = CFCR_NOT_ENOUGH_MEMORY; return status; } // копирование пикселей в изображение tmp int bufsize = width*(bpp == 8 ? 1:3);// число байт в строке, с возможным выравниваием BYTE* b = (BYTE*)tmp->pPixels; for (int i = 0; i < height; i++) { memcpy(b, pixels, bufsize); b+= bufsize; pixels += line_width; } image->SetImage(tmp); awpReleaseImage(&tmp); return status; }
bool CLBPTrackCompare::LoadCheckTrack(const char* lpFileName) { bool res = CNCCPTrackCompare::LoadCheckTrack(lpFileName); this->m_checklbp.Clear(); if (res) { for (int i = 0; i < this->m_pcheck->GetNumImages(); i++) { awpImage* img = this->m_pcheck->GetImage(i); awpImage* dscr = NULL; int descrSize = 59; int imgHeight = 16; awpCreateImage(&dscr, descrSize, imgHeight, 1, AWP_DOUBLE); awpLBPGridDescriptor(img, dscr, NULL, 4, 4, AWP_LBP_U2R1, true, 1); TLFImage* lfimg = new TLFImage(); lfimg->SetImage(dscr); this->m_checklbp.Add(lfimg); } } return res; }
/* Image segmentation main function */ bool DoSegmentation(awpImage* input, TSegmentationOptions& options, TLFObjectList* list) { bool result = false; if (input == NULL || list == NULL) return result; // cluster sgments if (options.segmentationType == 0) return result; TLFImage source; awpImage* tmp = NULL; double alfa = 1; if (options.needResize) { int w = options.imageWidth; int h = w*input->sSizeY / input->sSizeX; awpResizeNip(input, &tmp, w,h); } else awpCopyImage(input, &tmp); awpConvert(tmp, AWP_CONVERT_3TO1_BYTE); source.SetImage(tmp); TLFTileScanner scanner; scanner.SetBaseHeight(options.baseHeight); scanner.SetBaseWidth(options.baseWidth); scanner.GetParameter(0)->SetValue(options.tileOverlap); scanner.Scan(source.GetImage()->sSizeX, source.GetImage()->sSizeY); // list->Clear(); if (scanner.GetFragmentsCount() > 0) { for (int i = 0; i < scanner.GetFragmentsCount(); i++) { awpRect rect = scanner.GetFragmentRect(i); TLFSegmentationResult* sr = CreateFeature(options.baseFeature, &rect); if (sr != NULL) { sr->Process(&source); if (options.needResize) { alfa = (double)input->sSizeX / (double)options.imageWidth; sr->GetRect()->Scale(alfa); } list->Add(sr); } } } // filtering if (options.selectionCriteria == 0) { for (int i = list->GetCount() - 1; i >= 0; i--) { TLFSegmentationResult* sr = (TLFSegmentationResult*)list->Get(i); if (sr->Value() < options.moreThen) list->Delete(i); } } else if (options.selectionCriteria == 1) { for (int i = list->GetCount() - 1; i >= 0; i--) { TLFSegmentationResult* sr = (TLFSegmentationResult*)list->Get(i); if (sr->Value() > options.lessThen) list->Delete(i); } } else { for (int i = list->GetCount() - 1; i >= 0; i--) { TLFSegmentationResult* sr = (TLFSegmentationResult*)list->Get(i); if (sr->Value() < options.minValue || sr->Value() > options.maxValue) list->Delete(i); } } _AWP_SAFE_RELEASE_(tmp) result = true; return result; }