二维码识别项目zxing横屏改为竖屏
第1步:
在AndroidManifest中将CaptureActivity的screenOrientation属性做如下修改:
android:screenOrientation="portrait"
第2步:
我们要把摄像头预览景调为竖向
CameraConfigurationManager类中的setDesiredCameraParameters()方法中添加如下代码:
// 使摄像头旋转90度
setDisplayOrientation(camera, 90);
然后在CameraConfigurationManager类的最后添加setDisplayOrientation()方法:
/*改变照相机成像的方向的方法*/
protected void setDisplayOrientation(Camera camera, int angle) {
Method downPolymorphic = null;
try {
downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
if (downPolymorphic != null)
downPolymorphic.invoke(camera, new Object[]{angle});
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} }
最后在CameraConfigurationManager中的initFromCameraParameters()方法的Log.d(TAG, "Screen resolution: " + screenResolution);句后面添加如下代码,这段代码是为了解决摄像头竖过来后图像拉伸的问题:
//为竖屏添加
Point screenResolutionForCamera = new Point();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
if (screenResolution.x < screenResolution.y) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
}
// cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera);
第3步:
CameranManager类中getFramingRectInPreview()方法将:
// 下面为横屏模式
rect.left = rect.left * cameraResolution.x / screenResolution.x;
rect.right = rect.right * cameraResolution.x / screenResolution.x;
rect.top = rect.top * cameraResolution.y / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
改为:
// 下面为竖屏模式
rect.left = rect.left * cameraResolution.y / screenResolution.x;
rect.right = rect.right * cameraResolution.y / screenResolution.x;
rect.top = rect.top * cameraResolution.x / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
第4部:
在DecodeHandler类中的decode(byte[] data, int width, int height)方法中,在buildLuminanceSource调用前添加如下代码:
//竖屏
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width; // Here we are swapping, that's the difference to #11
width = height;
height = tmp;
data = rotatedData;
最后:
还是不行的话,就修改PlanarYUVLuminanceSource类,如果没有这个类就从其他地方copy。
PlanarYUVLuminanceSource类中的getRow()方法为识别条形码部分,
getMatrix()方法为识别二维码部分
renderCroppedGreyscaleBitmap()方法为生成获取的码图部分
将getRow()中的:
int offset = (y + top) * dataWidth + left;
getMatrix()中的:
int inputOffset = top * dataWidth + left;
inputOffset += dataWidth;
renderCroppedGreyscaleBitmap()中的:
int inputOffset = top * dataWidth + left;
inputOffset += dataWidth;
这些语句中dataWidth全部替换为dataHeight
同时将PlanarYUVLuminanceSource构造方法中:
if (left + width > dataWidth || top + height > dataHeight) {
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
}
dataWidth与dateHeight中互换位置即可。
二维码识别项目zxing横屏改为竖屏的更多相关文章
- Android二维码开源项目zxing用例简化和生成二维码、条形码
上一篇讲到:Android二维码开源项目zxing编译,编译出来后有一个自带的測试程序:CaptureActivity比較复杂,我仅仅要是把一些不用的东西去掉,用看起来更方便,二维码和条形码的流行性自 ...
- Android二维码开源项目zxing编译
ZXing是一个开放源代码的,用Java实现的多种格式的1D/2D条码图像处理库,它包括了联系到其它语言的port.Zxing能够实现使用手机的内置的摄像头完毕条形码的扫描及解码.该项目可实现的条形码 ...
- C#/.net 通过js调用系统相机进行拍照,图片无损压缩后进行二维码识别
这两天撸了一个需求,通过 JS 调用手机后置相机,进行拍照扫码.前台实现调用手机相机,然后截取图片并上传到后台的功能.后台接收传过来的图片后,通过调用开源二维码识别库 ZXing 进行二维码数据解析 ...
- Android二维码识别 开源项目ZXing的编译
Android二维码识别 开源项目ZXing的编译 Android端的条形码/二维码识别功能 因为手机端的输入不是很方便,所以条形码/二维码的扫描是一种很有效的解决手段. 比较流行的手机应用中,常用的 ...
- Python zxing 库解析(条形码二维码识别)
各种扫码软件 最近要做个二维码识别的项目,查到二维码识别有好多开源的不开源的软件 http://www.oschina.net/project/tag/238/ Zbar 首先试了一下Zbar,pyt ...
- 实例源码--ZXing识别条形码和二维码识别源码
下载源码 技术要点: 1.ZXing库的 使用 2.识别条形码和二 维码 3.自定义视图 4.源码带有非常详 细的中文注释 ...... 详细介绍: 1.ZXing库 ZXing是个很经典的条码/ ...
- 使用zxing二维码识别
1.多二维码识别 (同一张图片中多二维码识别) 直接上代码舒服: pom文件: <!-- QR Code --> <dependency> <groupId>com ...
- 有关python下二维码识别用法及识别率对比分析
最近项目中用到二维码图片识别,在python下二维码识别,目前主要有三个模块:zbar .zbarlight.zxing. 1.三个模块的用法: #-*-coding=utf-8-*- import ...
- 基于opencv3.0和下的条形码与二维码识别
其中对条码与二维码的识别分为以下4个步骤 1. 利用opencv和Zbar(或者Zxing)对标准的条形码图片(即没有多余背景干扰,且图片没有倾斜)进行解码,将解码信息显示出来,并与原始信息对比. 2 ...
随机推荐
- javaSpring学习总结day_01
本文章用于总结自己学习知识,有不足或错误之处清谅解. bean.xml 文件的读取方式: ClassPathXmlApplicationContext: 它是只能加载类路径下的配置文件 推荐 1.加载 ...
- Python学习day07 - Python进阶(1) 内置方法
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- 最新二进制安装部署kubernetes1.15.6集群---超详细教程
00.组件版本和配置策略 00-01.组件版本 Kubernetes 1.15.6 Docker docker-ce-18.06.1.ce-3.el7 Etcd v3.3.13 Flanneld v0 ...
- redux在react项目中的应用
今天想跟大家分享一下redux在react项目中的简单使用 1 1.redux使用相关的安装 yarn add redux yarn add react-redux(连接react和redux) 2. ...
- mybatis-环境配置-基本案例-和hibernate区别
Mybatis第一天 1. Mybatis介绍 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了goo ...
- 2018-10-31-C#-7.0-使用下划线忽略使用的变量
title author date CreateTime categories C# 7.0 使用下划线忽略使用的变量 lindexi 2018-10-31 14:4:9 +0800 2018-10- ...
- windows API 第八篇 _tcsicmp _stricmp _wcsicmp _mbsicmp
这些函数都是比较字符串小写的,忽略大写,出入的字符串都将按照小写比较Perform a lowercase comparison of strings. 函数原型: int _stricmp( con ...
- JZOJ5822 【NOIP提高A组模拟2018.8.16】 量子纠缠
这是一道很巧妙的题目. 今早,我调了好久,终于将它切掉了-- 题目 Description Input 第一行包含一个正整数 m,代表操作数. 接下来 m 行,每行可能有以下形式: 1 s 代表将数字 ...
- InnoDB: Error number 24 means ‘Too many open files’
一.问题的描述 备份程序 执行前滚的时候报错.(-apply-log) InnoDB: Errornumber 24 means 'Too many open files'. InnoDB: Some ...
- hadooplinux服务连接window平台问题
window eclipse下有hadoop 服务插件可以安装方便开发,今天突然发现连接不上做测试,鼓捣了一下.大多是因为端口问题 9000是DFS端口 50020是IPC服务端口,50070是web ...