QR code scanning area is determined

QR code scanning is often used in projects, but there is a headache, that is, the scanning area is not accurate enough, many people do it manually, rectOfInterest is the scanning range, the default is the upper left corner (0,0, 1,1) This is the default, fullscreen, with a maximum of 1. Through practice, it is found that (0,0,1,1) is a bit pitted. It is actually (y,x,h,w), that is, the coordinates y,x are the height and width (h,w). Of course, the calculation method is not very accurate, and this place is too pitted, and finally I found a method to share it, which is very accurate.

//监听
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InputChangeNotification) name:AVCaptureInputPortFormatDescriptionDidChangeNotification object:nil];

//设置
- (void)InputChangeNotification {
    AVCaptureMetadataOutput *output = self.session.outputs.firstObject;
    output.rectOfInterest = [self.previewLayer metadataOutputRectOfInterestForRect:self.scanRect];
}

//self.session //会话
//self.previewLayer //取景视图
//metadataOutputRectOfInterestForRect:最终是用这个方法转化到实际扫描范围坐标系的。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325255152&siteId=291194637