         UIDevice.current.setValue(oldOrientationValue.rawValue, forKey: "orientation")
         delegate!.cameraFinished(self)
     }
-    
+
     func resetThumbImages(){
         ULuii.image = UIImage(named:"gray.png")
         URuii.image = UIImage(named:"gray.png")
         LLuii.image = UIImage(named:"gray.png")
         LRuii.image = UIImage(named:"gray.png")
     }
-    
+
     @IBAction func captureImage(_ sender: UIButton){
-        let connection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo)
-        
-        stillImageOutput?.captureStillImageAsynchronously(from: connection) { imageBuffer, error in
-            if((imageBuffer) != nil){
-                let imageData: Data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageBuffer)
-                let UIImageFromData = UIImage(data: imageData)
-                
-                var  orient = UIImageOrientation.right;
-                if(self.rawOrient == "Right"){//case Right // 90 deg CW
-                    orient = UIImageOrientation.down
-                }
-                else if(self.rawOrient == "Left"){ //case Left // 90 deg CCW
-                    orient = UIImageOrientation.up
-                }
-                else if(self.rawOrient == "Up"){ //case Up // default orientation
-                    orient = UIImageOrientation.right
-                }
-                else if(self.rawOrient == "Down"){ //case Down // 180 deg rotation
-                    orient = UIImageOrientation.left
-                }
-                
-                
-                let oImage = UIImage(cgImage: (UIImageFromData?.cgImage!)!, scale: CGFloat(0.0), orientation: orient)
-                
-                let orientedAndScaledNSData: Data =
-                    UIImageJPEGRepresentation(self.sizeUIImage(image: oImage, size: self.getCGFloat()), 0.84)!
-                
-                self.badgeCounter += 1;
-                let fileName = self.generateFileName()
-                let path = self.mediaDir + "/" + fileName
-                let thumbPath = self.thumbDir + "/" + fileName
-                if self.filemgr.createFile(atPath: path, contents: orientedAndScaledNSData, attributes: nil) {
-                    let thumbData = self.thumbGen.createThumbOfImage(thumbPath, data: orientedAndScaledNSData)
-                    self.badgeCount.text = String(self.badgeCounter)
-                    if(self.quadState == 0) {self.ULuii.image = UIImage(data: thumbData, scale: 1); self.quadState = 1}
-                    else if(self.quadState == 1) {self.URuii.image = UIImage(data: thumbData, scale: 1); self.quadState = 2}
-                    else if(self.quadState == 2) {self.LLuii.image = UIImage(data: thumbData, scale: 1); self.quadState = 3}
-                    else if(self.quadState == 3) {self.LRuii.image = UIImage(data: thumbData, scale: 1); self.quadState = 0}
-                }else{
-                    print("failed to write image to path: " + path)
+        if(canTakePhoto){
+            canTakePhoto = false;
+            let connection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo)
+
+            stillImageOutput?.captureStillImageAsynchronously(from: connection) { imageBuffer, error in
+                if((imageBuffer) != nil){
+                    let imageData: Data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageBuffer)
+                    let UIImageFromData = UIImage(data: imageData)
+
+                    var  orient = UIImageOrientation.right;
+                    if(self.rawOrient == "Right"){//case Right // 90 deg CW
+                        orient = UIImageOrientation.down
+                    }
+                    else if(self.rawOrient == "Left"){ //case Left // 90 deg CCW
+                        orient = UIImageOrientation.up
+                    }
+                    else if(self.rawOrient == "Up"){ //case Up // default orientation
+                        orient = UIImageOrientation.right
+                    }
+                    else if(self.rawOrient == "Down"){ //case Down // 180 deg rotation
+                        orient = UIImageOrientation.left
+                    }
+
+                    let oImage = UIImage(cgImage: (UIImageFromData?.cgImage!)!, scale: CGFloat(0.0), orientation: orient)
+
+                    let orientedAndScaledNSData: Data =
+                        UIImageJPEGRepresentation(self.sizeUIImage(image: oImage, size: self.getCGFloat()), 0.84)!
+
+                    self.badgeCounter += 1;
+                    let fileName = self.generateFileName()
+                    let path = self.mediaDir + "/" + fileName
+                    let thumbPath = self.thumbDir + "/" + fileName
+                    if self.filemgr.createFile(atPath: path, contents: orientedAndScaledNSData, attributes: nil) {
+                        let thumbData = self.thumbGen.createThumbOfImage(thumbPath, data: orientedAndScaledNSData)
+                        self.badgeCount.text = String(self.badgeCounter)
+                        if(self.quadState == 0) {self.ULuii.image = UIImage(data: thumbData, scale: 1); self.quadState = 1}
+                        else if(self.quadState == 1) {self.URuii.image = UIImage(data: thumbData, scale: 1); self.quadState = 2}
+                        else if(self.quadState == 2) {self.LLuii.image = UIImage(data: thumbData, scale: 1); self.quadState = 3}
+                        else if(self.quadState == 3) {self.LRuii.image = UIImage(data: thumbData, scale: 1); self.quadState = 0}
+                    }else{
+                        print("failed to write image to path: " + path)
+                    }
+                    self.canTakePhoto = true;
                 }
             }
         }

    override var prefersStatusBarHidden : Bool {
        return true
    }
    
    override var shouldAutorotate : Bool {
        return false
    }

            self.beginSession();
        })
    }

    //MARK: AVFoundation Implementation
    func beginSession(){
        let currentDevice: UIDevice = UIDevice.current
