首页 文章

级联分类器HAAR LBP建议

提问于
浏览
0

我正在使用OpenCV和python来训练HAAR和LBP分类器来检测视频帧中的白细胞 . 由于问题基本上是2D,因此它应该比开发其他对象分类器更容易,并且视频帧之间存在很大的一致性 .

到目前为止,我一直在使用本教程:

http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html

这是视频的示例帧,我试图检测较小的明亮物体:
enter image description here

正面图像: - > nubmer = 60 - > filetype = JPG - > width = 50 - > height = 80
enter image description here

enter image description here

enter image description here

负片图像: - >数字= 600 - > filetype = JPG - > width = 50 - > height = 80
enter image description here

enter image description here

enter image description here

注:在视频中的所有帧中提取负图像作为随机框,然后我简单地删除我认为包含的任何单元格,即正图像 .

设置了问题的图像后,我按照编码知识的说明继续运行分类器:

find ./positive_images -iname "*.jpg" > positives.txt

find ./negative_images -iname "*.jpg" > negatives.txt

perl bin/createsamples.pl positives.txt negatives.txt samples 1500  "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 0.1 -maxyangle 0.1 maxzangle 0.1 -maxidev 40 -w 50 -h 80"

find ./samples -name '*.vec' > samples.txt

./mergevec samples.txt samples.vec

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\
-numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 60\
-numNeg 600 -w 50 -h 80 -mode ALL -precalcValBufSize 16384\
-precalcIdxBufSize 16384

这会引发错误:

无法填充临时阶段的训练数据集 . 分支培训终止 .

但是如果我尝试使用不同的参数,则使用HAAR和LBP生成文件'cascade.xml',更改minHitRate和maxFalseAlarmRate .

为了在我的图像上测试分类器,我有一个python脚本

import cv2

imagePath = "./examples/150224_Luc_1_MMImages_1_0001.png"
cascPath = "../classifier/cascade.xml"

leukocyteCascade = cv2.CascadeClassifier(cascPath)
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
leukocytes = leukocyteCascade.detectMultiScale(
    gray,
    scaleFactor=1.2,
    minNeighbors=5,
    minSize=(30, 70),
    maxSize=(60, 90),
    flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
print "Found {0} leukocytes!".format(len(leukocytes))

# Draw a rectangle around the leukocytes
for (x, y, w, h) in leukocytes:
    cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)

cv2.imwrite('output_frame.png',image)

这不是找到我想要的对象,当我用不同的参数运行它时有时会发现其他时间为0的67个对象,但不是我试图检测的对象 . 任何人都可以帮我调整代码以正确找到对象 . 非常感谢

1 回答

  • 1

    当您提供OpenCV的图像不足时,有时会抛出该错误 . 你的“ train dataset ”太小了,无法继续前进 .

    你能提供更积极的形象吗?我认为60可以用于某些对象,但通常人们提供的方式不止于此 .

    我在你的命令中注意到的另一件事是你提供的负像与你的阳性样本完全相同 . createsamples 所做的是将你的正面放在你的底片上,并使用底片作为背景,因此常用 **bg**.txt 文件名 . 如果你可以使用大于你的肯定的负数,我肯定会尝试 .

    您发布的图像中的白细胞也很模糊 . 如果他们的积极因素和样本模糊,而不是你的测试 detectMultiscale ,那么我怀疑OpenCV会找到它们,至少它赢得了't stick to them, so to speak. I see that that is the video you are using. You'可能已经完成了这个,但是让你保持视频仍然足以让OpenCV发挥其魔力!

    另外一件事,我会先为这些函数提供最小参数,直到你确切知道你在做什么为止 . 默认设置有一个原因:它们适用于大多数人 . 使您的样品和 traincascade -w-h 参数相同 . 让它们变小 . Make sure only the object you are trying to detect is in your positives . OpenCV可以检测大于指定尺寸的所有对象 . 这将通过减少检测可能出错的数量来帮助您确定是否存在其他类型的问题 .

    要尝试的事情:

    • 简化:删除您默认的所有额外参数 .

    • 指定与您知道的功能相同的宽度和高度,这些功能将小于您尝试检测的功能

    • 确保您的阳性和样品不模糊

    • 提供更多积极因素(也可能是否定因素)

    • 上面没有提到的一个:将你的 -minNeighbors 减少到2或3只是为了看它是否被检测到 . 如果不是,你需要重新开始 .

相关问题