我的问题是:如何将我的“自己的”haarcascade XML 用于 marilena + flartoolkit?我一直在疯狂地搜索,在这里偶然发现了这个:
http://www.moment77.se/flash-classes/code-snippets/convert-haar-cascades-from-xml-to-actionscript/
但是 PHP 脚本不起作用,屏幕仍然空白,我也尝试了我朋友的服务器。
我还可以做些什么?还是其他人能够执行它?还有其他方法吗?
我的问题是:如何将我的“自己的”haarcascade XML 用于 marilena + flartoolkit?我一直在疯狂地搜索,在这里偶然发现了这个:
http://www.moment77.se/flash-classes/code-snippets/convert-haar-cascades-from-xml-to-actionscript/
但是 PHP 脚本不起作用,屏幕仍然空白,我也尝试了我朋友的服务器。
我还可以做些什么?还是其他人能够执行它?还有其他方法吗?
我通过做两件事让它工作。
echo
count
(至少对于我的示例数据)最终代码如下所示
<?php
$xml = simplexml_load_file('haarcascades.xml');
$stages = $xml->haarcascade_frontalface_alt->stages->_;
for($s = 0; $s < count($stages); $s++){
$trees = $stages[$s]->trees->_;
if($s == 0)
echo "
tree = firstTree = new FeatureTree(". $stages[$s]->stage_threshold.");";
else
echo "
tree = tree.next = new FeatureTree(\". $stages[$s]->stage_threshold.\");";
for($t = 0; $t < count($trees); $t++){
$r1 = str_replace(" ", ",", trim(substr($trees[$t]->_->feature->rects->_[0], 0, strlen($trees[$t]->_->feature->rects->_[0])-1)));
$r2 = str_replace(" ", ",", trim(substr($trees[$t]->_->feature->rects->_[1], 0, strlen($trees[$t]->_->feature->rects->_[1])-1)));
$th = $trees[$t]->_->threshold;
$lv = $trees[$t]->_->left_val;
$rv = $trees[$t]->_->right_val;
if($t == 0)
echo "
feature = tree.firstFeature = new Feature2Rects($th, $lv, $rv, [$r1], [$r2]);";
else if($t == (count($trees) -1))
echo "
feature.next = new Feature2Rects($th, $lv, $rv, [$r1], [$r2]);";
else
echo "
feature = feature.next = new Feature2Rects($th, $lv, $rv, [$r1], [$r2]);";
}
}
$xml->haarcascade_frontalface_alt
创建计数时注意用法吗?这已更改,因为我使用的 xml 在顶部看起来像这样
<?xml version="1.0"?>
<opencv_storage>
<haarcascade_frontalface_alt type_id="opencv-haar-classifier">
<size>20 20</size>
<stages>
您需要将该名称更改为您的顶级节点的名称。
输出看起来像这样(但更长)
feature = tree.firstFeature = new Feature2Rects(-0.0951507985591888, 0.6470757126808167, 0.4017286896705627, [5,3,10,9,-1], [5,6,10,3,3]);
feature = feature.next = new Feature2Rects(6.2702340073883533e-003, 0.3999822139739990, 0.5746449232101440, [15,2,4,10,-1], [15,2,2,10,2]);