Face API : ps

This commit is contained in:
VE10-Sanjeev 2022-05-24 13:13:57 +05:30
parent 193a93a123
commit 3d8d0a7e0d
4 changed files with 78 additions and 61 deletions

View File

@ -984,6 +984,7 @@ class PD_Controller extends REST_Controller {
{
$pd_details['complete_override_data'] = json_encode($pd_details['complete_override_data']);
$pd_details['completed_on'] = date('Y-m-d H:i:s');
$this->toMakeFaceBoundingBox($exist_pd_details);
}
if(array_key_exists('link',$pd_details))
@ -11863,13 +11864,15 @@ public function getCompaniesListsFromGeneralFormRawJSONV2_post()
}
$this->response($data,REST_Controller::HTTP_OK);
}
public function facemark_get(){
$get = $this->get('pd');//pdid 3184
// public function facemark_get(){
public function toMakeFaceBoundingBox($master_details){
// $pdid = $this->get('pd');//pdid 3184 comment this
$pdid = $master_details[0]['pd_id'];
$bounding_box = array();
if(!empty($get)){
$master_details = $this->PD_Model->getPDMasterDetails($get);
if($master_details[0]['pd_status'] !== COMPLETED){
$db_result = $this->PD_Model->selectCustomRecords(array('faceapi_result'),array('pd_id' => $get),PDTRIGGER);
if(!empty($pdid)){
// $master_details = $this->PD_Model->getPDMasterDetails($pdid);//comment this
if($master_details[0]['pd_status'] == COMPLETED && $master_details[0]['facemark_image_generated'] == 0){
$db_result = $this->PD_Model->selectCustomRecords(array('faceapi_result'),array('pd_id' => $pdid),PDTRIGGER);
$string = $db_result[0]['faceapi_result'];
// echo gettype($string);
$my_array = json_decode($string,true);
@ -11881,38 +11884,49 @@ public function getCompaniesListsFromGeneralFormRawJSONV2_post()
$bounding_box[$i]['Similarity'] = $arr[$i]['Similarity'];
}
}
$where_condition_array = array('fk_pd_id' => $get,'isactive' => 1,'image_key' => "selfie_with_person_met");
$where_condition_array = array('fk_pd_id' => $pdid,'isactive' => 1,'image_key' => "selfie_with_person_met");
$img_result = $this->PD_Model->selectCustomRecords(array('pd_document_id','pd_document_name','pd_document_title','image_key'),$where_condition_array,PDDOCUMENTS);
$image_name = $img_result[0]['pd_document_name'];
$bucketname = LENDER_BUCKET_NAME_PREFIX.$master_details[0]['fk_lender_id'];
$key = 'pd'.$get.'/'.$image_name;
$bucketname = LENDER_BUCKET_NAME_PREFIX.$master_details[0]['fk_lender_id'];
$key = 'pd'.$pdid.'/'.$img_result[0]['pd_document_name'];
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes');
$destination_path = $this->external_path."/pd_reports/". $get ."/".$image_name;
//$getimage = getcontent first ($singed_uri)
$image_name = file_put_contents($destination_path, file_get_contents($singed_uri));
// $image_name = "sample.png";
// $destination_path = $this->external_path."/pd_reports/". $get ."/".$image_name;
// $temp_image_name = "sample.png";
$temp_image_name = "face_api_image.png";
$destination_path = $this->external_path."/pd_reports/". $pdid ."/".$temp_image_name;
file_put_contents($destination_path, file_get_contents($singed_uri));
faceapi::toMakeFaceBoundingBox($temp_image_name,$bounding_box,$destination_path);
faceapi::toMakeFaceBoundingBox($image_name,$bounding_box,$destination_path);
// save table s3
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = 'Given PDID ';
$data['details'] = $bounding_box;
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Given PDID is Not in Completed Status';
$key = 'pd'.$pdid.'/'.$temp_image_name;
$sourcefile = $destination_path;
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile);
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
// print_r($s3result);die();
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
{
$this->db->WHERE('pd_id',$pdid)->UPDATE(PDTRIGGER,array('facemark_image_generated' => 1));
unlink($destination_path);
}
// $data['dataStatus'] = true;
// $data['status'] = REST_Controller::HTTP_OK;
// $data['msg'] = 'Given PDID ';
// $data['details'] = $bounding_box;
}
}else{
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'PDID is Not Available';
// else{
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_NO_CONTENT;
// $data['msg'] = 'Given PDID is Not in Completed Status';
// }
}
$this->response($data,REST_Controller::HTTP_OK);
// else{
// $data['dataStatus'] = false;
// $data['status'] = REST_Controller::HTTP_NO_CONTENT;
// $data['msg'] = 'PDID is Not Available';
// }
// $this->response($data,REST_Controller::HTTP_OK);
}

View File

@ -2,18 +2,17 @@
class faceapi
{
private static $current_pd_id = null;
public static function toMakeFaceBoundingBox($image_name,$BoundingBox,$destination_path){
$get_image_format = explode(".",$image_name);
$image_format = $get_image_format[1];
if($image_format == 'png'){
$img = imagecreatefrompng($destination_path);
}else if($image_format == 'jpeg'){
$img = imagecreatefromjpeg($destination_path);
}else if($image_format == 'jpg'){
$img = imagecreatefromjpg($destination_path);
}
// $image_format = $get_image_format[1];
$img = imagecreatefrompng($destination_path);
// if($image_format == 'png'){
// $img = imagecreatefrompng($destination_path);
// }else if($image_format == 'jpeg'){
// $img = imagecreatefromjpeg($destination_path);
// }else if($image_format == 'jpg'){
// $img = imagecreatefromjpg($destination_path);
// }
$red = imagecolorallocate($img, 255, 0, 0);
@ -30,21 +29,25 @@ class faceapi
$Top_coordinate = ($BoundingBox[$i]['Top'] * $imageheight) ;
$Face_width = ($BoundingBox[$i]['Width'] * $imagewidth) ;
$Face_height = ($BoundingBox[$i]['Height'] * $imageheight) ;
$Similarity = round($BoundingBox[$i]['Similarity'])."%";
$Similarity = round($BoundingBox[$i]['Similarity']);
$x1 = $Left_coordinate;
$y1 = $Top_coordinate;
self::DrawLine($x1,$y1,$Face_width,$Face_height,$Similarity,$img,$image_format,$destination_path);
self::DrawLine($x1,$y1,$Face_width,$Face_height,$Similarity,$img,$destination_path);
}
}
public static function DrawLine($x1,$y1,$Face_width,$Face_height,$Similarity,$img,$image_format,$destination_path){
// 70 - green
// 70 below red
$color = imagecolorallocate($img, 0, 153, 0);
public static function DrawLine($x1,$y1,$Face_width,$Face_height,$Similarity,$img,$destination_path){
if($Similarity >= 70 ){// above 70 green
$color = imagecolorallocate($img, 0, 153, 0);
}else if($Similarity < 70 ){// below 70 red
$color = imagecolorallocate($img, 255, 0, 0);
}
$Similarity = $Similarity." %";
//TOP LINe
$t_x1 = $x1;
$t_y1 = $y1;
@ -62,17 +65,17 @@ class faceapi
$imgl = self::imagelinethick($img,$t_x1,$t_y1,$b_x1,$b_y1,$color,7);//left line
$imgl = self::imagelinethick($img,$t_x2,$t_y2,$b_x2,$b_y2,$color,7);//right line
// apppath / doc la roboto.tff
$string = str_replace("sample.png", "roboto.ttf", $destination_path);
imagettftext($img, 20, 0, ($t_x1), ($t_y1-5), $color,$string, $Similarity);
$font = APPPATH."docs/roboto.ttf";
imagettftext($img, 20, 0, ($t_x1), ($t_y1-5), $color,$font, $Similarity);
imagepng($img, $destination_path);
// imagepng($img, "face4.png");
if($image_format == 'png'){
imagepng($img, $destination_path);
}else if($image_format == 'jpeg'){
imagejpeg($img, $destination_path);
}else if($image_format == 'jpg'){
imagejpg($img, $destination_path);
}
// if($image_format == 'png'){
// imagepng($img, $destination_path);
// }else if($image_format == 'jpeg'){
// imagejpeg($img, $destination_path);
// }else if($image_format == 'jpg'){
// imagejpg($img, $destination_path);
// }
}

View File

@ -541,8 +541,8 @@ class smc_creditpd
static function getFinalRemarksSectionData($section)
{
$json = json_decode($section['json'],true);
$customer_behaviour = array(1 => 'Others',2 => 'Rude',3 => 'Polite');
$pd_officer_recommandations = array(2=>'Positive',3=>'Negative',5=>'Refer to Credit',0=>'Others');
$customer_behaviour = array("1" => 'Others',"2" => 'Rude',"3" => 'Polite');
$pd_officer_recommandations = array("2"=>'Positive',"3"=>'Negative',"5"=>'Refer to Credit',"0"=>'Others');
$json['pd_officer_recommendation_name'] = isset($value['pd_officer_recommendation'])? $pd_officer_recommandations [ $value['pd_officer_recommendation_name'] ] : 'NA';
$json['customer_behaviour_name'] = (isset($value['customer_behaviour']) ? $customer_behaviour [ $value['customer_behaviour'] ] : 'NA');
// echo 'json***';

File diff suppressed because one or more lines are too long