/// <summary> /// Gets the capture image parameters with Json web token credentials. /// Json web token credentials contains enable or disable, if enable then need to provide jwt secret and token. /// </summary> /// <returns> /// Byte array of image with transaction Id and image extension. /// </returns> public CaptureDto CaptureImage(Capture model) { var captureDto = new CaptureDto(); Log.Information("[HCM][Capture Image][Req]" + "[" + JsonSerializer.Serialize(model) + "]"); try { var(statusCode, errorResult) = LockerManagementValidator.PayloadValidator(LockerConfiguration, model.JwtCredentials.IsEnabled, model.JwtCredentials.Secret, model.JwtCredentials.Token, PayloadTypes.CaptureImage, model.LockerId, model.TransactionId, null, CaptureType.Photo); if (statusCode != StatusCode.Status200OK) { return(CaptureMapper.ToError(new CaptureDto { StatusCode = statusCode, Error = errorResult })); } var result = LockerHelper.CapturePhoto(model, LockerConfiguration); captureDto = CaptureMapper.ToObject(result); Log.Information("[HCM][Capture Image][Res]" + "[Success]"); } catch (Exception ex) { Log.Error("[HCM][Capture Image]" + "[" + ex + "]"); return(CaptureMapper.ToError(new CaptureDto { StatusCode = StatusCode.Status500InternalServerError, Error = new Common.Exceptions.ApplicationException(ApplicationErrorCodes.InternalServerError, ex.Message) })); } return(captureDto); }
public static CaptureDto ToError(this CaptureDto model) { return(new CaptureDto() { StatusCode = model.StatusCode, Error = model.Error }); }
public static CaptureDto ToObject(this CaptureDto model) { return(new CaptureDto() { LockerId = model.LockerId, TransactionId = model.TransactionId, CaptureImage = new Entities.Locker.Image(model.CaptureImage.ImageExtension, model.CaptureImage.ImageData), StatusCode = StatusCode.Status200OK, Error = null }); }
/// <summary> /// Image byte array preparation by open library. /// </summary> /// <returns> /// Byte array of image with image extension. /// </returns> public static CaptureDto CapturePhoto(DataObjects.Models.Capture model, AppSettings lockerConfiguration) { byte[] imageBytes = null; Mat frame = new Mat(); using (VideoCapture capture = new VideoCapture(0)) { capture.Open(0); if (capture.IsOpened()) { capture.Read(frame); Bitmap imageBitmapData = BitmapConverter.ToBitmap(frame); Bitmap snapshot = new Bitmap(imageBitmapData); string photofileName = string.Format(@"{0}.jpeg", lockerConfiguration.Locker.LockerId + "_" + Guid.NewGuid()); //This saved real picture to physical location. if (lockerConfiguration.CaptureImage.IsSnapShotToLocal) { snapshot.Save(photofileName, ImageFormat.Jpeg); } imageBytes = ToByteArray(snapshot, ImageFormat.Jpeg); Log.Debug("[HCM][Locker Helper][Capture Photo]" + "[Photo taken File : " + photofileName + "]"); } else { Log.Debug("[HCM][Locker Helper][Capture Photo]" + "[Cannot take picture if the camera isn't capturing image!]"); } var captureResponse = new CaptureDto(model.TransactionId, model.LockerId, "jpeg", imageBytes); // End using camera capture.Release(); return(captureResponse); } }