跳转至

图像对齐

图像对齐

Public Functions

Type Name
int SaigeInitializeAlignModule (const int gpuIndex, const int sourceWidth, const int sourceHeight, const int targetWidth, const int targetHeight)
使用默认预设(prototype_a)激活Saige Alignment功能的函数。
int SaigeInitializeAlignModuleWithPreset (const int gpuIndex, const int sourceWidth, const int sourceHeight, const int targetWidth, const int targetHeight, const char * preset)
指定对齐方式(preset)激活Saige Alignment功能的函数。
int SaigeFinalizeAlignModule ()
结束Saige Alignment功能的函数。释放功能使用的GPU内存。
int SaigeAlignImageFromByteArray (const unsigned char * sourceImage, const int sourceWidth, const int sourceHeight, const int sourceChannel, const unsigned char * targetImage, const int targetWidht, const int targetHeight, const int targetChannel, unsigned int flag, unsigned char * croppedSourceImage)
将Source图像的位置调整到与Target图像匹配的函数。
int SaigeAlignImageFromByteArrayWithCoord (const unsigned char * sourceImage, const int sourceWidth, const int sourceHeight, const int sourceChannel, const unsigned char * targetImage, const int targetWidht, const int targetHeight, const int targetChannel, unsigned int flag, unsigned char * croppedSourceImage, int * cropCoords)
SaigeAlignImageFromByteArray的扩展版本,同时返回结果图像中所含Source区域的像素坐标。
int SaigeAlignImageFromFile (const char * sourceImagePath, const char * targetImagePath, int * cropWidth, int * cropHeight, int * cropChannel, unsigned char * croppedSourceImage)
Not Implemented

Public Functions Documentation

SaigeInitializeAlignModule

使用默认预设(prototype_a)激活Saige Alignment功能的函数。

int SaigeInitializeAlignModule (
    const int gpuIndex,
    const int sourceWidth,
    const int sourceHeight,
    const int targetWidth,
    const int targetHeight
) 

等同于SaigeInitializeAlignModuleWithPreset(gpuIndex, ..., nullptr)。 prototype_a将Source图像的位置调整到与Target图像匹配并裁剪它,因此Source图像必须大于 Target图像。需要其他对齐方式时,请使用SaigeInitializeAlignModuleWithPreset。

Parameters:

  • gpuIndex 要使用的GPU索引。使用CPU时传入-1。
  • sourceWidth Source图像的宽度。
  • sourceHeight Source图像的高度。
  • targetWidth Target图像的宽度。
  • targetHeight Target图像的高度。

Returns:

errorCode 成功时返回0,失败时返回错误代码。

SaigeInitializeAlignModuleWithPreset

指定对齐方式(preset)激活Saige Alignment功能的函数。

int SaigeInitializeAlignModuleWithPreset (
    const int gpuIndex,
    const int sourceWidth,
    const int sourceHeight,
    const int targetWidth,
    const int targetHeight,
    const char * preset
) 

各preset的行为如下。 * prototype_a(默认):scan↔ODB,Source > Target。从Source中裁剪Target大小的区域(可使用GPU) * scan_odb_mutual_information:img↔odb,Source = Target。基于互信息的平移对齐 * scan_scan_correlation:img↔img(不同光照),Source = Target。基于相关性的平移对齐

平移方式(scan_odb_mutual_information、scan_scan_correlation)不使用模型,与gpuIndex 无关,均在CPU上运行;Source与Target尺寸不同时返回错误代码-419302。对齐结果及坐标的含义请参考 SaigeAlignImageFromByteArrayWithCoord。每个进程只保留一个preset,再次调用时会释放之前的配置 并以新的preset初始化。

Parameters:

  • gpuIndex 要使用的GPU索引。使用CPU时传入-1。
  • sourceWidth Source图像的宽度。
  • sourceHeight Source图像的高度。
  • targetWidth Target图像的宽度。
  • targetHeight Target图像的高度。
  • preset preset名称或<tt>.saigealign文件路径。传入名称时使用 SAIGE_HOME/SaigeVision/module/SaigeAlignment/checkpoint/<preset>.saigealign。 传入nullptr或空字符串时使用prototype_a。

Returns:

errorCode 成功时返回0,失败时返回错误代码。preset文件不存在时返回FILE_NOT_FOUND。

SaigeFinalizeAlignModule

结束Saige Alignment功能的函数。释放功能使用的GPU内存。

int SaigeFinalizeAlignModule () 

Returns:

errorCode 成功时返回0,失败时返回错误代码。

SaigeAlignImageFromByteArray

将Source图像的位置调整到与Target图像匹配的函数。

int SaigeAlignImageFromByteArray (
    const unsigned char * sourceImage,
    const int sourceWidth,
    const int sourceHeight,
    const int sourceChannel,
    const unsigned char * targetImage,
    const int targetWidht,
    const int targetHeight,
    const int targetChannel,
    unsigned int flag,
    unsigned char * croppedSourceImage
) 

结果图像为Target尺寸,因此croppedSourceImage的大小应为 targetWidth * targetHeight * sourceChannel。无论输入通道顺序如何,结果均以RGB顺序返回。 各preset的行为请参考SaigeInitializeAlignModuleWithPreset。

Parameters:

  • sourceImage Source图像的字节数组。
  • sourceWidth Source图像的宽度。
  • sourceHeight Source图像的高度。
  • sourceChannel Source图像的通道。
  • targetImage Target图像的字节数组。
  • targetWidht Target图像的宽度。
  • targetHeight Target图像的高度。
  • targetChannel Target图像的通道。
  • flag 输入图像标志。输入为BGR顺序(例如OpenCV cv::imread)时必须指定SAIGE_IMAGE_BGR, 否则视为RGB顺序。
  • croppedSourceImage 接收与Target对齐后的Source图像的字节数组。

Returns:

errorCode 成功时返回0,失败时返回错误代码。

SaigeAlignImageFromByteArrayWithCoord

SaigeAlignImageFromByteArray的扩展版本,同时返回结果图像中所含Source区域的像素坐标。

int SaigeAlignImageFromByteArrayWithCoord (
    const unsigned char * sourceImage,
    const int sourceWidth,
    const int sourceHeight,
    const int sourceChannel,
    const unsigned char * targetImage,
    const int targetWidht,
    const int targetHeight,
    const int targetChannel,
    unsigned int flag,
    unsigned char * croppedSourceImage,
    int * cropCoords
) 

对齐行为与SaigeAlignImageFromByteArray相同,并以Source图像坐标系的(x1, y1, x2, y2) 将结果图像中所含的Source区域写入cropCoords。 * prototype_a:从Source中裁剪的区域,始终位于Source范围内。 * scan_odb_mutual_information / scan_scan_correlation:Source平移(dx, dy),坐标为 (-dx, -dy, W - dx, H - dy),可能为负数或超过W、H。超出结果范围的部分被裁掉,空白区域填充0。 对齐失败时返回原始Source和(0, 0, W, H),无法与实际平移量为0的情况区分。

Parameters:

  • cropCoords 用于接收结果图像中所含Source区域像素坐标(x1, y1, x2, y2)的int[4]数组。 如果不需要坐标,可以传入nullptr。

Returns:

errorCode 成功时返回0,失败时返回错误代码。

SaigeAlignImageFromFile

Not Implemented

int SaigeAlignImageFromFile (
    const char * sourceImagePath,
    const char * targetImagePath,
    int * cropWidth,
    int * cropHeight,
    int * cropChannel,
    unsigned char * croppedSourceImage
)