Commit 10b7da10 authored by Nguyen Huy Nhat Anh's avatar Nguyen Huy Nhat Anh

add frame

parent 6316f203
...@@ -78,12 +78,12 @@ public class SB_KYC_SDK { ...@@ -78,12 +78,12 @@ public class SB_KYC_SDK {
//Call API face //Call API face
//input: UIImage //input: UIImage
public func eKycFaceMatch(imageFace: CVPixelBuffer, imageCardFront: CVPixelBuffer, imageCardBack: CVPixelBuffer, completion: @escaping CompletionHandle) { public func eKycFaceMatch(imageFace: Data, imageCardFront: Data, imageCardBack: Data, completion: @escaping CompletionHandle) {
SBKValidateInput.shared.validateFace(imageFace: imageFace) {[weak self] data in SBKValidateInput.shared.validateFace(imageFace: imageFace) {[weak self] data in
guard self != nil else { return } guard self != nil else { return }
if data { if data {
Global.imageCard1 = SBKValidateInput.shared.convertCVPixelToUIImage(pixelBuffer: imageCardFront).pngData() Global.imageCard1 = imageCardFront
Global.imageCard2 = SBKValidateInput.shared.convertCVPixelToUIImage(pixelBuffer: imageCardFront).pngData() Global.imageCard2 = imageCardBack
let imageFaceUI = SBKValidateInput.shared.convertCVPixelToUIImage(pixelBuffer: imageFace).pngData() let imageFaceUI = SBKValidateInput.shared.convertCVPixelToUIImage(pixelBuffer: imageFace).pngData()
SBOCRRequest.shared.processFace(image: imageFaceUI! , pathURL: Global.url_face, idBack: "", idFront: "") {(errorCode,data) -> Void in SBOCRRequest.shared.processFace(image: imageFaceUI! , pathURL: Global.url_face, idBack: "", idFront: "") {(errorCode,data) -> Void in
......
...@@ -13,8 +13,15 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate { ...@@ -13,8 +13,15 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate {
let nibName = "SBKValidateCardView" let nibName = "SBKValidateCardView"
var contentView:UIView? var contentView:UIView?
// @IBOutlet public weak var viewCamera: UIView!
// @IBOutlet public weak var btnTakePhoto: UIButton!
@IBOutlet public weak var viewCamera: UIView! @IBOutlet public weak var viewCamera: UIView!
@IBOutlet public weak var btnTakePhoto: UIButton! @IBOutlet public weak var lbDescription: UILabel!
@IBOutlet public weak var lbCopyright: UILabel!
@IBOutlet public weak var lbStep: UILabel!
@IBOutlet public weak var btnCapture: UIButton!
@IBOutlet public weak var imgCaution: UIImageView!
public var captureSession: AVCaptureSession = AVCaptureSession() public var captureSession: AVCaptureSession = AVCaptureSession()
public var stillImageOutput: AVCapturePhotoOutput = AVCapturePhotoOutput() public var stillImageOutput: AVCapturePhotoOutput = AVCapturePhotoOutput()
...@@ -64,6 +71,14 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate { ...@@ -64,6 +71,14 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate {
} }
self.loadCamera() self.loadCamera()
let label = UILabel()
label.frame = CGRect(x: self.center.x - 50, y: self.frame.size.height / 8 + self.viewCamera.frame.origin.y - 40, width: 100, height: 20)
label.textAlignment = .center
label.text = self.typeCamera == TypeCard.FRONT ? "Use front" : "Use back"
label.textColor = UIColor.white
self.addSubview(label)
} }
func loadViewFromNib() -> UIView? { func loadViewFromNib() -> UIView? {
...@@ -80,7 +95,7 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate { ...@@ -80,7 +95,7 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate {
let topLeft = CGPoint(x: fWidth/2-squareWidth/3, y: fHeight/4) let topLeft = CGPoint(x: fWidth/2-squareWidth/3, y: fHeight/4)
if iconTakeCard != nil { if iconTakeCard != nil {
self.btnTakePhoto.setImage(iconTakeCard, for: .normal) self.btnCapture.setImage(iconTakeCard, for: .normal)
} }
if iconFrameTopLeft != nil { if iconFrameTopLeft != nil {
...@@ -212,8 +227,8 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate { ...@@ -212,8 +227,8 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate {
// self.captureSession.stopRunning() // self.captureSession.stopRunning()
// self.captureSession.removeOutput(self.videoDataOutput) // self.captureSession.removeOutput(self.videoDataOutput)
// self.captureSession.removeOutput(self.stillImageOutput) // self.captureSession.removeOutput(self.stillImageOutput)
let cropImage = self.cropImage(image: UIImage(data: imageData)!, rect: CGRect(x: UIImage(data: imageData)!.size.width / 20, y: UIImage(data: imageData)!.size.height * 6 / 20 , width: self.viewCamera.frame.size.width * 18 / 20, height: self.viewCamera.frame.size.width * 18 * 3 / 20 / 4), scale: 1.0) let cropImage = self.cropImage(image: UIImage(data: imageData)!, rect: CGRect(x: UIImage(data: imageData)!.size.width / 20, y: UIImage(data: imageData)!.size.height * 4.5 / 20 , width: self.viewCamera.frame.size.width * 18 / 20, height: self.viewCamera.frame.size.width * 18 * 3 / 20 / 4), scale: 1.0)
self.completionSuccessCardStep(nil, cropImage!.pngData()!, nil) self.completionSuccessCardStep(nil, cropImage!.pngData()!, nil)
} }
//Xử lý ảnh hiển thị //Xử lý ảnh hiển thị
...@@ -249,7 +264,7 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate { ...@@ -249,7 +264,7 @@ public class SBKValidateCardView: UIView, AVCapturePhotoCaptureDelegate {
if UIDevice.current.userInterfaceIdiom == .pad { if UIDevice.current.userInterfaceIdiom == .pad {
imageOutput = validateView.cropImage(image: imageInput, rect: CGRect(x: imageInput.size.width / 20, y: imageInput.size.height * 2 / 7, width: imageInput.size.width - imageInput.size.width/10, height: (imageInput.size.width - imageInput.size.width/10) * 3/4), scale: 1.0) imageOutput = validateView.cropImage(image: imageInput, rect: CGRect(x: imageInput.size.width / 20, y: imageInput.size.height * 2 / 7, width: imageInput.size.width - imageInput.size.width/10, height: (imageInput.size.width - imageInput.size.width/10) * 3/4), scale: 1.0)
} else { } else {
imageOutput = validateView.cropImage(image: imageInput, rect: CGRect(x: imageInput.size.width / 20, y: imageInput.size.height * 2 / 7, width: imageInput.size.width - imageInput.size.width/10, height: (imageInput.size.width - imageInput.size.width/10) * 3/4), scale: 1.0) imageOutput = validateView.cropImage(image: imageInput, rect: CGRect(x: imageInput.size.width / 20, y: imageInput.size.height * 1.5 / 7, width: imageInput.size.width - imageInput.size.width/10, height: (imageInput.size.width - imageInput.size.width/10) * 3/4 + 7), scale: 1.0)
} }
let ciimage = CIImage(image: imageOutput!) let ciimage = CIImage(image: imageOutput!)
...@@ -286,6 +301,7 @@ extension SBKValidateCardView: AVCaptureVideoDataOutputSampleBufferDelegate { ...@@ -286,6 +301,7 @@ extension SBKValidateCardView: AVCaptureVideoDataOutputSampleBufferDelegate {
self.completionSuccessCardStep(validateImageCard, nil, nil) self.completionSuccessCardStep(validateImageCard, nil, nil)
self.statusValidateImage = validateImageCard self.statusValidateImage = validateImageCard
self.lbDescription.text = validateImageCard.rawValue
} }
} }
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.3" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/> <device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<objects> <objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="SBKValidateCardView" customModule="SB_KYC_SDK" customModuleProvider="target"> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="SBKValidateCardView" customModule="SB_KYC_SDK" customModuleProvider="target">
<connections> <connections>
<outlet property="btnTakePhoto" destination="MUh-i4-cOT" id="XIX-vk-Xo9"/> <outlet property="btnCapture" destination="0tu-Uu-aZJ" id="hbb-5m-asu"/>
<outlet property="viewCamera" destination="vId-Gb-QYw" id="dO3-YL-g95"/> <outlet property="imgCaution" destination="Uu0-ZS-WyV" id="FwQ-r8-w9z"/>
<outlet property="lbCopyright" destination="Yoc-45-cmQ" id="3OV-hF-Q8k"/>
<outlet property="lbDescription" destination="wnG-jG-HwA" id="dai-gb-2uU"/>
<outlet property="lbStep" destination="miZ-LC-N58" id="nFu-j2-7oT"/>
<outlet property="viewCamera" destination="lKp-BC-igm" id="SQO-Z9-Rni"/>
</connections> </connections>
</placeholder> </placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
...@@ -19,36 +23,88 @@ ...@@ -19,36 +23,88 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="vId-Gb-QYw"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="bMq-BQ-SN5">
<rect key="frame" x="0.0" y="44" width="414" height="698"/> <rect key="frame" x="173.5" y="731.5" width="67" height="20.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Step 1/3" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="miZ-LC-N58">
<rect key="frame" x="10" y="3" width="47" height="14.5"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.54183894399999999" green="0.5419179797" blue="0.54181402919999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="miZ-LC-N58" secondAttribute="bottom" constant="3" id="0lx-4s-sHT"/>
<constraint firstItem="miZ-LC-N58" firstAttribute="leading" secondItem="bMq-BQ-SN5" secondAttribute="leading" constant="10" id="7aK-qy-Jmn"/>
<constraint firstAttribute="trailing" secondItem="miZ-LC-N58" secondAttribute="trailing" constant="10" id="Tib-gw-Wyo"/>
<constraint firstItem="miZ-LC-N58" firstAttribute="top" secondItem="bMq-BQ-SN5" secondAttribute="top" constant="3" id="dqu-js-W96"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
<integer key="value" value="3"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="lKp-BC-igm">
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
<color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view> </view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="MUh-i4-cOT"> <label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Use front" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Yoc-45-cmQ">
<rect key="frame" x="171.5" y="123.5" width="71" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<imageView hidden="YES" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Caution.png" translatesAutoresizingMaskIntoConstraints="NO" id="Uu0-ZS-WyV">
<rect key="frame" x="147" y="629" width="120" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="120" id="NyR-vg-E0a"/>
<constraint firstAttribute="height" constant="32" id="gHe-IN-Yuj"/>
</constraints>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0tu-Uu-aZJ">
<rect key="frame" x="182" y="782" width="50" height="50"/> <rect key="frame" x="182" y="782" width="50" height="50"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="50" id="dPQ-aO-sFP"/> <constraint firstAttribute="height" constant="50" id="MGa-aI-9ef"/>
<constraint firstAttribute="width" constant="50" id="nMV-8l-zek"/> <constraint firstAttribute="width" constant="50" id="hiM-7d-T1r"/>
</constraints> </constraints>
<state key="normal" image="iconCap.png"/> <state key="normal" image="iconCap.png"/>
<connections> <connections>
<action selector="onCapturePhoto:" destination="-1" eventType="touchUpInside" id="bv8-Oo-gSm"/> <action selector="onCapturePhoto:" destination="-1" eventType="touchUpInside" id="Vg0-NJ-EOP"/>
</connections> </connections>
</button> </button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wnG-jG-HwA">
<rect key="frame" x="205" y="681" width="4.5" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews> </subviews>
<viewLayoutGuide key="safeArea" id="hB9-pv-7hU"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints> <constraints>
<constraint firstItem="MUh-i4-cOT" firstAttribute="top" secondItem="vId-Gb-QYw" secondAttribute="bottom" constant="40" id="5HA-ie-rYI"/> <constraint firstItem="bMq-BQ-SN5" firstAttribute="top" secondItem="wnG-jG-HwA" secondAttribute="bottom" constant="30" id="3RZ-t3-RxF"/>
<constraint firstItem="vId-Gb-QYw" firstAttribute="top" secondItem="hB9-pv-7hU" secondAttribute="top" id="9yW-SW-kTY"/> <constraint firstItem="0tu-Uu-aZJ" firstAttribute="centerX" secondItem="hB9-pv-7hU" secondAttribute="centerX" id="446-x7-rap"/>
<constraint firstItem="vId-Gb-QYw" firstAttribute="leading" secondItem="tMz-JL-QhO" secondAttribute="leading" id="COE-Wm-3Sg"/> <constraint firstItem="0tu-Uu-aZJ" firstAttribute="top" secondItem="bMq-BQ-SN5" secondAttribute="bottom" constant="30" id="9ne-hi-Dep"/>
<constraint firstItem="hB9-pv-7hU" firstAttribute="bottom" secondItem="MUh-i4-cOT" secondAttribute="bottom" constant="30" id="G5T-sy-Cra"/> <constraint firstItem="bMq-BQ-SN5" firstAttribute="centerX" secondItem="hB9-pv-7hU" secondAttribute="centerX" id="Cej-FU-Dtq"/>
<constraint firstItem="MUh-i4-cOT" firstAttribute="centerX" secondItem="hB9-pv-7hU" secondAttribute="centerX" id="RAV-Ta-Xst"/> <constraint firstItem="lKp-BC-igm" firstAttribute="leading" secondItem="hB9-pv-7hU" secondAttribute="leading" id="Feg-QV-jKA"/>
<constraint firstAttribute="trailing" secondItem="vId-Gb-QYw" secondAttribute="trailing" id="U1Q-AI-Opp"/> <constraint firstItem="lKp-BC-igm" firstAttribute="top" secondItem="hB9-pv-7hU" secondAttribute="top" id="M7T-cU-AYs"/>
<constraint firstItem="Uu0-ZS-WyV" firstAttribute="centerX" secondItem="hB9-pv-7hU" secondAttribute="centerX" id="RJl-D9-e7j"/>
<constraint firstItem="hB9-pv-7hU" firstAttribute="trailing" secondItem="lKp-BC-igm" secondAttribute="trailing" id="V4W-de-wre"/>
<constraint firstItem="lKp-BC-igm" firstAttribute="top" secondItem="Yoc-45-cmQ" secondAttribute="bottom" constant="-100" id="ZhS-dd-cGP"/>
<constraint firstItem="hB9-pv-7hU" firstAttribute="bottom" secondItem="lKp-BC-igm" secondAttribute="bottom" id="bsH-Lw-Emb"/>
<constraint firstItem="wnG-jG-HwA" firstAttribute="top" secondItem="Uu0-ZS-WyV" secondAttribute="bottom" constant="20" id="eIh-l6-wou"/>
<constraint firstItem="wnG-jG-HwA" firstAttribute="centerX" secondItem="hB9-pv-7hU" secondAttribute="centerX" id="mg9-DV-NWp"/>
<constraint firstItem="Yoc-45-cmQ" firstAttribute="centerX" secondItem="hB9-pv-7hU" secondAttribute="centerX" id="qpt-JY-I2K"/>
<constraint firstItem="hB9-pv-7hU" firstAttribute="bottom" secondItem="0tu-Uu-aZJ" secondAttribute="bottom" constant="30" id="zb1-xI-WE2"/>
</constraints> </constraints>
<viewLayoutGuide key="safeArea" id="hB9-pv-7hU"/>
<point key="canvasLocation" x="133" y="154"/> <point key="canvasLocation" x="133" y="154"/>
</view> </view>
</objects> </objects>
<resources> <resources>
<image name="Caution.png" width="84.5" height="84.5"/>
<image name="iconCap.png" width="172" height="172"/> <image name="iconCap.png" width="172" height="172"/>
</resources> </resources>
</document> </document>
...@@ -22,6 +22,7 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -22,6 +22,7 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
@IBOutlet weak var viewCheckStep2: UIView! @IBOutlet weak var viewCheckStep2: UIView!
@IBOutlet weak var viewCheckStep3: UIView! @IBOutlet weak var viewCheckStep3: UIView!
@IBOutlet weak var imageDescription: UIImageView! @IBOutlet weak var imageDescription: UIImageView!
@IBOutlet weak var stackView: UIStackView!
private let captureSession = AVCaptureSession() private let captureSession = AVCaptureSession()
private lazy var previewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession) private lazy var previewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession)
...@@ -49,6 +50,7 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -49,6 +50,7 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
public var timeSpace: Int = 3 public var timeSpace: Int = 3
public var zoom: CGFloat = 1.0 public var zoom: CGFloat = 1.0
public var imageStartRecord: UIImage? public var imageStartRecord: UIImage?
public var checkStep: Int = 0
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
...@@ -108,11 +110,10 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -108,11 +110,10 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
if let viewWithTag = self.viewWithTag(1) { if let viewWithTag = self.viewWithTag(1) {
viewWithTag.removeFromSuperview() viewWithTag.removeFromSuperview()
} }
let originYLBCopyright = self.lbCopyright.frame.origin.y / 896 * self.bounds.height
let heightLBCopyright = self.lbCopyright.frame.height / 896 * self.bounds.height
let locationTop = originYLBCopyright + heightLBCopyright + 35
let originYLBDescription = self.lbDescription.frame.origin.y / 896 * self.bounds.height let locationTop = self.bounds.origin.y + 35
let originYLBDescription = self.stackView.frame.origin.y / 896 * self.bounds.height
let heightOval = originYLBDescription - locationTop let heightOval = originYLBDescription - locationTop
...@@ -153,11 +154,9 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -153,11 +154,9 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
} }
func createOverlay(frame: CGRect, xOffset: CGFloat, yOffset: CGFloat, radius: CGFloat) { func createOverlay(frame: CGRect, xOffset: CGFloat, yOffset: CGFloat, radius: CGFloat) {
let originYLBCopyright = self.lbCopyright.frame.origin.y / 896 * self.bounds.height let locationTop = self.bounds.origin.y + 35
let heightLBCopyright = self.lbCopyright.frame.height / 896 * self.bounds.height
let locationTop = originYLBCopyright + heightLBCopyright + 35
let originYLBDescription = self.lbDescription.frame.origin.y / 896 * self.bounds.height let originYLBDescription = self.stackView.frame.origin.y / 896 * self.bounds.height
let heightOval = originYLBDescription - locationTop let heightOval = originYLBDescription - locationTop
...@@ -211,45 +210,88 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -211,45 +210,88 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
let ciimage : CIImage = CIImage(cvPixelBuffer: pixelBuffer) let ciimage : CIImage = CIImage(cvPixelBuffer: pixelBuffer)
let imageView : UIImage = SBKValidateInput.shared.convertCIToUIImage(cmage: ciimage) let imageView : UIImage = SBKValidateInput.shared.convertCIToUIImage(cmage: ciimage)
if self.result![0] < self.result![1] { if self.result![0] < self.result![1] {
if statusFace == .STRAIGHTFACE && 0 <= self.timeRecord && self.timeRecord < self.timeSpace { // if statusFace == .STRAIGHTFACE && 0 <= self.timeRecord && self.timeRecord < self.timeSpace {
// if self.dataImageSuccess.count == 0 {
// self.dataImageSuccess.append(imageView.pngData()!)
// }
// self.completionSuccessFaceRecordStep(.FACE_STRAIGHT, nil, nil)
// if 1 <= self.timeRecord {
// self.lbDescription.textColor = UIColor.green
// self.lbDescription.text = " ".localized()
// }
// } else if statusFace != .STRAIGHTFACE && 1 <= self.timeRecord && self.timeRecord < self.timeSpace {
// self.lbDescription.textColor = UIColor.red
// self.lbDescription.text = " ".localized()
// self.completionSuccessFaceRecordStep(.FACE_STRAIGHT_FAILD, nil, nil)
// } else if statusFace == .TORIGHT && self.timeSpace <= self.timeRecord && self.timeRecord < self.timeSpace * 2 {
// self.lbDescription.textColor = UIColor.green
// self.lbDescription.text = " ".localized()
// self.completionSuccessFaceRecordStep(.FACE_RIGHT, nil, nil)
// if self.dataImageSuccess.count == 1 {
// self.dataImageSuccess.append(imageView.pngData()!)
// }
// } else if statusFace != .TORIGHT && self.timeSpace <= self.timeRecord && self.timeRecord < self.timeSpace * 2 {
// self.lbDescription.textColor = UIColor.red
// self.lbDescription.text = " ".localized()
// self.completionSuccessFaceRecordStep(.FACE_RIGHT_FAILD, nil, nil)
// } else if statusFace == .TOLEFT && self.timeSpace * 2 <= self.timeRecord && self.timeRecord < self.timeSpace * 3 {
// self.lbDescription.textColor = UIColor.green
// self.lbDescription.text = " ".localized()
// self.completionSuccessFaceRecordStep(.FACE_LEFT, nil, nil)
// if self.dataImageSuccess.count == 2 {
// self.dataImageSuccess.append(imageView.pngData()!)
// }
// } else if statusFace != .TOLEFT && self.timeSpace * 2 <= self.timeRecord && self.timeRecord < self.timeSpace * 3 {
// self.lbDescription.textColor = UIColor.red
// self.lbDescription.text = " ".localized()
// self.completionSuccessFaceRecordStep(.FACE_LEFT_FAILD, nil, nil)
// }
if statusFace == .STRAIGHTFACE && self.checkStep == 0 {
if self.dataImageSuccess.count == 0 { if self.dataImageSuccess.count == 0 {
self.dataImageSuccess.append(imageView.pngData()!) self.dataImageSuccess.append(imageView.pngData()!)
} }
self.completionSuccessFaceRecordStep(.FACE_STRAIGHT, nil, nil) self.completionSuccessFaceRecordStep(.FACE_STRAIGHT, nil, nil)
if 1 <= self.timeRecord { self.lbDescription.textColor = UIColor.green
self.lbDescription.textColor = UIColor.green self.lbDescription.text = "Exactly".localized()
self.lbDescription.text = " ".localized() self.checkStep = 1
} self.viewCheckStep1.backgroundColor = UIColor.colorFromHexa("#FBA02E")
} else if statusFace != .STRAIGHTFACE && 1 <= self.timeRecord && self.timeRecord < self.timeSpace { } else if statusFace != .STRAIGHTFACE && self.checkStep == 0 {
self.lbDescription.textColor = UIColor.red self.lbDescription.textColor = UIColor.red
self.lbDescription.text = " ".localized() self.lbDescription.text = "Please look straight".localized()
self.viewCheckStep1.backgroundColor = UIColor.colorFromHexa("#FE3500")
self.completionSuccessFaceRecordStep(.FACE_STRAIGHT_FAILD, nil, nil) self.completionSuccessFaceRecordStep(.FACE_STRAIGHT_FAILD, nil, nil)
} else if statusFace == .TORIGHT && self.timeSpace <= self.timeRecord && self.timeRecord < self.timeSpace * 2 { } else if statusFace == .TORIGHT && self.checkStep == 1 {
self.lbDescription.textColor = UIColor.green self.lbDescription.textColor = UIColor.green
self.lbDescription.text = " ".localized() self.lbDescription.text = "Exactly".localized()
self.checkStep = 2
self.viewCheckStep2.backgroundColor = UIColor.colorFromHexa("#FBA02E")
self.completionSuccessFaceRecordStep(.FACE_RIGHT, nil, nil) self.completionSuccessFaceRecordStep(.FACE_RIGHT, nil, nil)
if self.dataImageSuccess.count == 1 { if self.dataImageSuccess.count == 1 {
self.dataImageSuccess.append(imageView.pngData()!) self.dataImageSuccess.append(imageView.pngData()!)
} }
} else if statusFace != .TORIGHT && self.timeSpace <= self.timeRecord && self.timeRecord < self.timeSpace * 2 { } else if statusFace != .TORIGHT && self.checkStep == 1 {
self.lbDescription.textColor = UIColor.red self.lbDescription.textColor = UIColor.red
self.lbDescription.text = " ".localized() self.lbDescription.text = "Please turn to the right".localized()
self.completionSuccessFaceRecordStep(.FACE_RIGHT_FAILD, nil, nil) self.completionSuccessFaceRecordStep(.FACE_RIGHT_FAILD, nil, nil)
} else if statusFace == .TOLEFT && self.timeSpace * 2 <= self.timeRecord && self.timeRecord < self.timeSpace * 3 { self.viewCheckStep2.backgroundColor = UIColor.colorFromHexa("#FE3500")
} else if statusFace == .TOLEFT && self.checkStep == 2 {
self.lbDescription.textColor = UIColor.green self.lbDescription.textColor = UIColor.green
self.lbDescription.text = " ".localized() self.lbDescription.text = "Exactly".localized()
self.checkStep = 3
self.viewCheckStep3.backgroundColor = UIColor.colorFromHexa("#FBA02E")
self.completionSuccessFaceRecordStep(.FACE_LEFT, nil, nil) self.completionSuccessFaceRecordStep(.FACE_LEFT, nil, nil)
if self.dataImageSuccess.count == 2 { if self.dataImageSuccess.count == 2 {
self.dataImageSuccess.append(imageView.pngData()!) self.dataImageSuccess.append(imageView.pngData()!)
} }
} else if statusFace != .TOLEFT && self.timeSpace * 2 <= self.timeRecord && self.timeRecord < self.timeSpace * 3 { } else if statusFace != .TOLEFT && self.checkStep == 2 {
self.lbDescription.textColor = UIColor.red self.lbDescription.textColor = UIColor.red
self.lbDescription.text = " ".localized() self.lbDescription.text = "Please turn to the left".localized()
self.completionSuccessFaceRecordStep(.FACE_LEFT_FAILD, nil, nil) self.completionSuccessFaceRecordStep(.FACE_LEFT_FAILD, nil, nil)
self.viewCheckStep3.backgroundColor = UIColor.colorFromHexa("#FE3500")
} }
} else { } else {
self.lbDescription.textColor = UIColor.red self.lbDescription.textColor = UIColor.red
self.lbDescription.text = " ".localized() self.lbDescription.text = "Incorrect face, please check!".localized()
self.completionSuccessFaceRecordStep(.FACE_FAKE, nil, nil) self.completionSuccessFaceRecordStep(.FACE_FAKE, nil, nil)
} }
} }
...@@ -257,8 +299,15 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -257,8 +299,15 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
if result![0] < result![1] { if result![0] < result![1] {
DispatchQueue.main.async { DispatchQueue.main.async {
self.checkStartRecord = true self.checkStartRecord = true
self.lbDescription.textColor = UIColor.green self.lbDescription.textColor = UIColor.white
self.lbDescription.text = " ".localized()//"Bạn đã sẵn sàng. Hãy bắt đầu!" if !self.checkStatusRecord {
self.checkStatusRecord = true
self.timeRecord = 0
self.checkStep = 0
self.viewCheckStep1.backgroundColor = UIColor.colorFromHexa("#333333")
self.viewCheckStep2.backgroundColor = UIColor.colorFromHexa("#333333")
self.viewCheckStep3.backgroundColor = UIColor.colorFromHexa("#333333")
}
self.completionSuccessFaceRecordStep(.FACE_READY, nil, nil) self.completionSuccessFaceRecordStep(.FACE_READY, nil, nil)
} }
} else { } else {
...@@ -277,7 +326,7 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -277,7 +326,7 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
self.startTimer() self.startTimer()
self.checkStatusRecord = true self.checkStatusRecord = true
self.timeRecord = 0 self.timeRecord = 0
let image = UIImage(named: "player_stop", in: Bundle(for: SBKTutorialVC.self), compatibleWith: nil) //let image = UIImage(named: "player_stop", in: Bundle(for: SBKTutorialVC.self), compatibleWith: nil)
//self.btnRecord.setImage(imageStartRecord ?? image, for: .normal) //self.btnRecord.setImage(imageStartRecord ?? image, for: .normal)
} }
} }
...@@ -336,11 +385,9 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -336,11 +385,9 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
overlayView.backgroundColor = UIColor.black.withAlphaComponent(0.6) overlayView.backgroundColor = UIColor.black.withAlphaComponent(0.6)
let path = CGMutablePath() let path = CGMutablePath()
let originYLBCopyright = self.lbCopyright.frame.origin.y / 896 * self.bounds.height let locationTop = self.bounds.origin.y + 35
let heightLBCopyright = self.lbCopyright.frame.height / 896 * self.bounds.height
let locationTop = originYLBCopyright + heightLBCopyright + 35
let originYLBDescription = self.lbDescription.frame.origin.y / 896 * self.bounds.height let originYLBDescription = self.stackView.frame.origin.y / 896 * self.bounds.height
let heightOval = originYLBDescription - locationTop let heightOval = originYLBDescription - locationTop
...@@ -381,6 +428,8 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -381,6 +428,8 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
} else { } else {
let statusString = self.checkFaceRightLeft(landmarks: results[0].landmarks!) let statusString = self.checkFaceRightLeft(landmarks: results[0].landmarks!)
self.startTimer()
DispatchQueue.global().async { DispatchQueue.global().async {
self.didOutput(pixelBuffer: image, statusFace: statusString) self.didOutput(pixelBuffer: image, statusFace: statusString)
} }
...@@ -393,7 +442,7 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -393,7 +442,7 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
self.completionSuccessFaceRecordStep(.NO_FACE, nil, nil) self.completionSuccessFaceRecordStep(.NO_FACE, nil, nil)
} else { } else {
self.lbDescription.textColor = UIColor.red self.lbDescription.textColor = UIColor.red
self.lbDescription.text = " ".localized() self.lbDescription.text = "Incorrect face, please check!".localized()
DispatchQueue.global().async { DispatchQueue.global().async {
self.didOutput(pixelBuffer: image, statusFace: .ERROR) self.didOutput(pixelBuffer: image, statusFace: .ERROR)
...@@ -415,10 +464,6 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -415,10 +464,6 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
try? imageRequestHandler.perform([faceDetectionRequest]) try? imageRequestHandler.perform([faceDetectionRequest])
} }
func startTimer() {
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(setLableRecord(timer:)), userInfo: nil, repeats: true)
}
func resetRecord() { func resetRecord() {
self.numberPass = 0 self.numberPass = 0
self.numberTrue = 0 self.numberTrue = 0
...@@ -479,6 +524,47 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele ...@@ -479,6 +524,47 @@ public class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDele
} }
func startTimer() {
switch self.checkStep {
case 0:
self.imageDescription.image = UIImage(named: "Scan-3@2x", in: Bundle(for: SBKTutorialVC.self), compatibleWith: nil)
self.lbDescription.textColor = UIColor.white
self.completionSuccessFaceRecordStep(nil, .STEP_FACE_STRAIGHT, nil)
self.lbDescription.text = "Please look straight".localized()//"vui lòng nhìn thẳng"
case 1:
self.imageDescription.image = UIImage(named: "Scan-5@2x", in: Bundle(for: SBKTutorialVC.self), compatibleWith: nil)
self.lbDescription.textColor = UIColor.white
self.completionSuccessFaceRecordStep(nil, .STEP_FACE_RIGHT, nil)
self.lbDescription.text = "Please turn to the right".localized()//"Quay sang phải"
case 2:
self.imageDescription.image = UIImage(named: "Scan-4@2x", in: Bundle(for: SBKTutorialVC.self), compatibleWith: nil)
self.lbDescription.textColor = UIColor.white
self.completionSuccessFaceRecordStep(nil, .STEP_FACE_LEFT, nil)
self.lbDescription.text = "Please turn to the left".localized()//"Quay sang trái"
case 3:
if self.dataImageSuccess.count > 2 {
DispatchQueue.main.async {
let data: [String: Any] = [
"imagestraight": self.dataImageSuccess[0],
"imageRight": self.dataImageSuccess[1],
"imageLeft": self.dataImageSuccess[2],
]
self.completionSuccessFaceRecordStep(nil, nil, data)
self.timeRecord = 0
self.resetRecord()
self.timer.invalidate()
}
} else {
self.lbDescription.textColor = UIColor.red
self.lbDescription.text = "Unsatisfactory, please try again!".localized()//"Chưa đạt yêu cầu, hãy thử lại!"
self.completionSuccessFaceRecordStep(.INVALID, nil, nil)
}
default:
break
}
}
func resizeImageFace(pixelBuffer: CVPixelBuffer) -> CVPixelBuffer { func resizeImageFace(pixelBuffer: CVPixelBuffer) -> CVPixelBuffer {
let validateView = SBKValidateInput.shared let validateView = SBKValidateInput.shared
let imageInput = validateView.convertCVPixelToUIImage(pixelBuffer: pixelBuffer) let imageInput = validateView.convertCVPixelToUIImage(pixelBuffer: pixelBuffer)
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<connections> <connections>
<outlet property="imageDescription" destination="qAP-z1-ph6" id="4WK-9l-Hhw"/> <outlet property="imageDescription" destination="qAP-z1-ph6" id="4WK-9l-Hhw"/>
<outlet property="lbDescription" destination="l4S-dU-FVT" id="7qE-CY-e4c"/> <outlet property="lbDescription" destination="l4S-dU-FVT" id="7qE-CY-e4c"/>
<outlet property="stackView" destination="lfu-gT-avH" id="UPQ-PC-13s"/>
<outlet property="viewBackground" destination="vtt-nP-K7e" id="p2H-QE-FHN"/> <outlet property="viewBackground" destination="vtt-nP-K7e" id="p2H-QE-FHN"/>
<outlet property="viewCheckStep1" destination="Ikb-Rh-oGt" id="gg1-L1-h5k"/> <outlet property="viewCheckStep1" destination="Ikb-Rh-oGt" id="gg1-L1-h5k"/>
<outlet property="viewCheckStep2" destination="q10-fa-3fY" id="YaT-X4-UMq"/> <outlet property="viewCheckStep2" destination="q10-fa-3fY" id="YaT-X4-UMq"/>
...@@ -57,7 +58,7 @@ ...@@ -57,7 +58,7 @@
<subviews> <subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ikb-Rh-oGt"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ikb-Rh-oGt">
<rect key="frame" x="0.0" y="0.0" width="68" height="6"/> <rect key="frame" x="0.0" y="0.0" width="68" height="6"/>
<color key="backgroundColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <color key="backgroundColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
<userDefinedRuntimeAttributes> <userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius"> <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
<integer key="value" value="3"/> <integer key="value" value="3"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment