我正在Windows 10上使用<?php
// THIS IS ESSENTIALLY THE SAME STORE CLASS AS YOU HAD
// EXCEPT THIS TIME WE CHANGED EVERYTHING CONNECTED WITH mysql[i]
// IN OTHER WORDS; THIS IS THE PDO EQUIVALENT OF YOUR STORE CLASS:
/***********************************************/
/****** BEGIN STORE CLASS DEFINITION ******/
/***********************************************/
class Store{
public $storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated;
//CREATE A STATIC PROPERTY TO HOLD YOUR DB-RESOURCE:
/**@var PDO $db*/
protected static $db;
public function __construct($storeID=NULL,$name=NULL,$contact=NULL,$address=NULL,$phone=NULL,$fax=NULL,$email=NULL,$webpage=NULL,$latitude=0,$longitude=0,$status=0,$created=NULL,$updated=NULL){
// JUST CALL THE DB CONNECTION METHOD ONCE AND USE THE HANDLE EVERYWHERE IN YOUR CODE LIKE SO:
self::establishDBConnection();
$this->storeID = $storeID;
$this->name = $name;
$this->contact = $contact;
$this->address = $address;
$this->phone = $phone;
$this->fax = $fax;
$this->email = $email;
$this->webpage = $webpage;
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->status = $status;
$this->created = $created;
$this->updated = $updated;
//$this->enabled=$enabled;
}
// TRY PUTTING YOUR DATABASE CONNECTION LOGIC IN ONE METHOD FOR SIMPLICITY:
public static function establishDBConnection() {
try {
if(static::$db){
return static::$db;
}else{
static::$db = new PDO('mysql:host='.DB_HOST.';dbname='. DB_NAMES,DB_ADMIN,DB_PWORD);
static::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return self::$db;
}
} catch (PDOException $e) {
// IF THERE WAS AN ANY KIND OF CONNECTION ERROR, "DIE IT OUT" TO THE OUTPUT STREAM:
die($e->getMessage());
}
}
public function toString(){
$s="StoreID: ".$this->storeID."<br/>";
$s.="Name: ".$this->name."<br/>";
$s.="Contact: ".$this->contact."<br/>";
$s.="Address: ".$this->address."<br/>";
$s.="Phone: ".$this->phone."<br/>";
$s.="Fax: ".$this->fax."<br/>";
$s.="E-mail: ".$this->email."<br/>";
$s.="Webpage: ".$this->webpage."<br/>";
$s.="Latitude: ".$this->latitude."<br/>";
$s.="Longitude: ".$this->longitude."<br/>";
$s.="Status: ".$this->status."<br/>";
$s.="Created: ".$this->created."<br/>";
$s.="Updated: ".$this->updated."<br/>";
return $s;
}
}
/***********************************************/
/******* END STORE CLASS DEFINITION *******/
/***********************************************/
function restoreStore($id){updateStoreStatus($id,UNVERIFIED);}
function verifyStore($id){updateStoreStatus($id,VERIFIED);}
function unverifyStore($id){updateStoreStatus($id,UNVERIFIED);}
function trashStore($id){updateStoreStatus($id,RECYCLING_BIN);}
function updateStoreStatus($id,$status){
$db = Store::establishDBConnection();
$q = $db->prepare('UPDATE stores SET status=:status, updated=:updated WHERE storeID=:storeID');
$date = date("Y-m-d H:i:s");
$q->execute(array(
'status' => $status,
'updated' => $date,
'storeID' => $id,
));
$q->execute();
return 1;
}
function emptyStores(){
$rcBin = RECYCLING_BIN;
$db = Store::establishDBConnection();
$q = $db->prepare('DELETE FROM stores WHERE status=:rcBIN');
$q->bindParam(':rcBIN', $rcBin);
$q->execute();
return 1;
}
function deleteStore($id){
$db = Store::establishDBConnection();
$q=$db->prepare('DELETE FROM stores WHERE storeID=:storeID');
$q->bindParam(':storeID', $id);
$q->execute();
return 1;
}
function insertStore($store){
$db = Store::establishDBConnection();
$store->created =date("Y-m-d H:i:s"); //overwrite dates
$store->updated =$store->created;
$sql = 'INSERT INTO stores (name, contact, address, phone, fax, email, webpage, latitude, longitude, status, created, updated) ';
$sql .= 'values (:name, :contact, :address, :phone, :phone, :fax, :email, :webpage, :latitude, :longitude, :status, :created, :updated)';
if($q = $db->prepare($sql)){
$arrValues = array(
"name" =>$store->name,
"contact" =>$store->contact,
"address" =>$store->address,
"phone" =>$store->phone,
"fax" =>$store->fax,
"email" =>$store->email,
"webpage" =>$store->webpage,
"latitude" =>$store->latitude,
"longitude" =>$store->longitude,
"status" =>$store->status,
"created" =>$store->created,
"updated" =>$store->updated
);
$q->execute($arrValues);
}
else{
printf($db->errorCode());
exit();
}
$q = $db->prepare('SELECT storeID FROM stores WHERE name=:name AND created=:created');
$q->bindParam(":name", $store->name);
$q->bindParam(":created", $store->created);
$objSID = $q->fetch(PDO::FETCH_OBJ);
if(strlen($objSID->storeID)>0) return $objSID->storeID;
else return ERROR_DEFAULT;
}
//PRE-CONDITION: email, password, billingID, groupID must exist
function updateStore($store){
$db = Store::establishDBConnection();
//BEGIN ERROR CHECKING -------------------------------
//END ERROR CHECKING ---------------------------------
$store->updated=date("Y-m-d H:i:s"); //overwrite dates
$sql = 'UPDATE stores SET name=:name, contact=:contact, address=:address, phone=:phone, fax=:fax, email=:email, webpage=:webpage, latitude=:latitude, longitude=:longitude, status=:status, updated=:updated WHERE storeID=:storeID';
$q = $db->prepare($sql);
$arrValues = array(
"name" =>$store->name,
"contact" =>$store->contact,
"address" =>$store->address,
"phone" =>$store->phone,
"fax" =>$store->fax,
"email" =>$store->email,
"webpage" =>$store->webpage,
"latitude" =>$store->latitude,
"longitude" =>$store->longitude,
"status" =>$store->status,
"created" =>$store->created,
"updated" =>$store->updated,
"storeID" =>$store->storeID
);
$q->execute($arrValues);
$q = $db->prepare('SELECT storeID FROM stores WHERE name=:name AND created=:created');
$q->bindParam(":name", $store->username);
$q->bindParam(":created", $store->created);
$objSID = $q->fetch(PDO::FETCH_OBJ);
if(strlen($objSID->storeID)>0) return $objSID->storeID;
else return ERROR_DEFAULT;
}
function getStore($id){
$db = Store::establishDBConnection();
$sql = 'SELECT storeID, name, contact, address, phone, fax, email, webpagee, latitud, longitude, status, created, updated FROM stores WHERE storeID=:storeID';
$q = $db->prepare($sql);
$q->bindParam(":storeID", $id);
$q->execute();
$storeObj = $q->fetch(PDO::FETCH_OBJ);
$s = NULL;
if($storeObj){
$s = new Store($storeObj->storeID, $storeObj->name, $storeObj->contact, $storeObj->address, $storeObj->phone, $storeObj->fax, $storeObj->email, $storeObj->webpage, $storeObj->latitude, $storeObj->longitude, $storeObj->status, $storeObj->created, $storeObj->updated);
}
return $s;
}
function getStoreCount($filter = NULL){
$db = Store::establishDBConnection();
$sql = 'SELECT COUNT(*) as count FROM stores';
if($filter != NULL) $sql .= " WHERE " . $filter;
$q = $db->prepare($sql);
$q->execute();
$objCount = $q->fetch(PDO::FETCH_OBJ);
$count = $objCount->count;
return $count;
}
function getStores($filter = NULL, $order = NULL, $start = 0, $limit = 10){
$db = Store::establishDBConnection();
$sql ='SELECT storeID, name, contact, address, phone, fax, email, webpage, latitude, longitude, status, created, updated FROM stores ';
if($filter != NULL) $sql .= " WHERE " . $filter;
if($order != NULL) $sql .= " ORDER BY ". $order;
if($limit > 0) $sql .= ' LIMIT ' . $start .',' . $limit;
$q = $db->prepare($sql);
$q->execute();
$arrData = $q->fetch(PDO::FETCH_ASSOC);
$stores = array();
foreach($arrData as $intKey=>$objData){
$store = new Store($objData->storeID, $objData->name, $objData->contact, $objData->address, $objData->phone, $objData->fax, $objData->email, $objData->webpage, $objData->latitude, $objData->longitude, $objData->status, $objData->created, $objData->updated);
$stores[] = $store;
}
return $stores;
}
?>
为dlib 18.18
编译QT 5.6
。
我已阅读所有建议(http://dlib.net/faq.html#Whyisdlibslow):AVX或SSE4指令,发布模式。
示例“webcam_face_pose_ex.exe”就像魅力一样,非常快。
问题:
但是当我在QT下使用frontal_face_detector时,帧速率非常低。
640x480~170 ms
1920x1080~1100 ms
系统配置:Windows 10(x64),Intel Core i5-3550,QT 5.6,OpenCV 3.1.0,MinGW 4.9.2
尝试在dlib和opencv中使用AVX / SSE4指令的所有变体。 但我认为这是不同的 - 因为这个例子很快。 QT中使用的代码也是从示例中复制粘贴的,即使没有GUI。
在调试模式下,640x480帧需要6-7秒才能处理。
.pro文件转储:
MinGW 4.9.2
答案 0 :(得分:0)
Dlib人脸检测器是基于头的,不依赖于用于编译dlib.lib本身的编译器标志。
Dlib有一个记录的选项“-DUSE_AVX_INSTRUCTIONS = ON”,但是如果您没有使用CMAKE构建并将dlib / cmake文件包含在CMakeLists.txt
中它将无效您应该将编译器的AVX启用标志添加到项目中以使其快速运行
解决方案是在.pro文件中添加一个显式参数:
QMAKE_CXXFLAGS_RELEASE + = -mavx
当您在Qt Creator中编译项目时,您可以看到它如何调用编译器以及使用了哪些标志。确保你有-mavx标志。 -msse2的工作速度要慢20%