在将原本于 20.05版本中的程序拷贝至20.11.02版本环境中出现报错
报错: 预处理数据集时报错2001 images_exist函数抛出异常
是由于将程序开始处的两处路径改为绝对路径时导致。
*
* ***********************************
* *** Set Input/Output paths. ***
* ***********************************
*
* Directory with image data.
ImageDir := 'C:/Users/xx/Desktop/新建文件夹 (2)/ddd'
* Directory with ground truth segmentation images.
SegmentationDir := 'C:/Users/xx/Desktop/新建文件夹 (2)/labels'
查看该函数后,发现halcon例程中的list_image_and_annotation_files函数在拆分图像路径时有问题,仅考虑了相对路径。问题来自于这句
*
* Get file paths of images relative to ImageDir.
tuple_regexp_match (ImageDirectories[0], '.*?' + ImageDir, CommonBasePathImage)
tuple_regexp_replace (ImageDirectories, CommonBasePathImage, '', ImageDirectoriesRel)
在匹配字符串ImageDirectories[0]和ImageDir时未找到路径字符串相同部分,CommonBasePathImage为""导致第二句在分离相对路径时失效,从而导致后续读取图像时路径出错
修改read_dl_dataset_segmentation函数里的list_image_and_annotation_files函数中将原代码
*
* Get file paths of images relative to ImageDir.
tuple_regexp_match (ImageDirectories[0], '.*?' + ImageDir, CommonBasePathImage)
tuple_regexp_replace (ImageDirectories, CommonBasePathImage, '', ImageDirectoriesRel)
更改为
* Get file paths of images relative to ImageDir.
tuple_regexp_match (ImageDirectories[0], '.*?' + ImageDir, CommonBasePathImage)
if(CommonBasePathImage = '')
ImageDirectoriesRel:=''
else
tuple_regexp_replace (ImageDirectories, CommonBasePathImage, '', ImageDirectoriesRel)
endif
同理,修改label图像路径拆分程序
* Get paths of annotation files relative to AnnotationDir.
tuple_regexp_match (AnnoDirectories[0], '.*?' + AnnotationDir, CommonBasePathAnno)
tuple_regexp_replace (AnnoDirectories, CommonBasePathAnno, '', AnnoDirectoriesRel)
改为
* Get paths of annotation files relative to AnnotationDir.
tuple_regexp_match (AnnoDirectories[0], '.*?' + AnnotationDir, CommonBasePathAnno)
if(CommonBasePathAnno = '')
AnnoDirectoriesRel := ''
else
tuple_regexp_replace (AnnoDirectories, CommonBasePathAnno, '', AnnoDirectoriesRel)
endif
后续程序即可正常