我的问题是:如何将我自己的haarcascade用于marilena + flartoolkit?我疯狂地在谷歌上搜索,在这里偶然发现了以下内容:
http://www.moment77.se/flash-classes/code-snippets/convert-haar-cascades-from-xml-to-actionscript/
然而,PHP脚本就是不起作用,屏幕仍然是空白的,我也尝试过我朋友的服务器。
我还能做什么?或者是其他人能够执行它?还有别的办法吗?
发布于 2013-03-19 23:59:56
我通过做两件事让它工作。
first 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]);https://stackoverflow.com/questions/15504146
复制相似问题