鼻炎吃什么药效果最好| 什么样的人着床晚| 王加申念什么| 流泪痣是什么意思| 石灰水是什么| 饮食不规律会导致什么| 月经不调吃什么药效果好| 左腿疼是什么原因| 鱼胶是什么东西| 什么叫大数据| 你的美丽让你带走是什么歌| 早上起床腰酸痛是什么原因| 有趣是什么意思| 脂蛋白高说明什么问题| 命硬的人有什么特征| 辣椒炒肉用什么肉| 甲状腺在人体什么位置| 梦见捡鸡蛋是什么意思| 黑长直是什么意思| 声援是什么意思| 成功的反义词是什么| 更年期什么症状| 绿色的大便是什么原因| 8月7日是什么星座| 睾头囊肿是什么意思| 洋葱有什么好处| 海澜之家属于什么档次| bff是什么意思| crp高是什么原因| 喝水就打嗝是什么原因| 自刎是什么意思| 肚子痛吃什么药好| mA是什么| 行经是什么意思| 量贩式ktv是什么意思| 翌日什么意思| 显现是什么意思| 木棉花什么时候开花| 志心皈命礼是什么意思| 四川地震前有什么预兆| 不是省油的灯是什么意思| 什么是辐照食品| 什么是点天灯| 破涕为笑是什么意思| 天罗地网是什么生肖| 鸡枞是什么东西| 什么时候去西藏旅游最好| 产后什么时候来月经正常| 6月28日什么星座| 小孩肚子痛吃什么药| 经常头疼是什么原因引起的| 结婚登记需要什么证件| 凛冽是什么意思| 月亮星座代表什么意思| 金酒属于什么酒| 十二月十四日是什么星座| 传播什么| 舛是什么意思| 小狗能看见什么颜色| 六月十一是什么星座| 嗓子疼看什么科室| 五光十色是什么生肖| 尿液浑浊是什么原因| 爱慕内衣什么档次| 大便带血丝是什么原因| 空调开除湿有什么作用| 医共体是什么意思| 抗核抗体弱阳性说明什么| 过火是什么意思| 甲状腺有什么作用| hk是什么意思| 富字五行属什么| 西游记什么时候写的| 胃疼是什么症状| 50pcs是什么意思| 好事多磨是什么意思| 叶酸什么时候吃合适| 女生补气血吃什么好| 猴子下山的故事告诉我们什么| 什么能什么力| 施华洛世奇算什么档次| 什么的麦田| 陈皮泡水喝有什么功效| 拉k是什么意思| ds是什么意思| 义务兵是什么意思| 大量出汗是什么原因引起的| 1988年什么命| 耳朵背后有痣代表什么| 韬光养晦什么意思| 心悸什么意思| 马云父母是做什么的| 总胆汁酸高是什么原因| 看见双彩虹有什么征兆| 副主任医师什么级别| 生殖器疱疹是什么病| 观音位置摆放什么方向| 吃什么有助于消化| 叶芽是什么| 7月14号是什么星座| 云雾茶属于什么茶| 中秋节送什么水果好| 纤尘是什么意思| 曹操姓什么| 香榧是什么东西| 广谱是什么意思| 肝内多发低密度影是什么意思| 意念灰是什么意思| 总胆红素高说明什么| 书生是什么生肖| 咳黄痰是什么原因| 睡莲为什么不开花| a型血可以接受什么血型| 县公安局局长是什么级别| 肠道易激惹综合症是什么症状| 长粉刺是什么原因| 舌头紫红色是什么原因| 西门子洗衣机不脱水是什么原因| 呃逆是什么意思| 嘴巴有异味是什么原因| 维生素e吃多了有什么副作用| 为什么一紧张就想拉屎| 男人前列腺在什么位置| 女人内火旺喝什么降火| 双侧胸膜局限性增厚是什么意思| 中暑了吃什么| 什么的铅笔| 眼睛看什么科| 白茶适合什么季节喝| 狭隘是什么意思| 王朔为什么不娶徐静蕾| 霸王龙吃什么| 梦见死人什么意思| 为什么下巴经常长痘痘| 速战速决的意思是什么| 什么是星座| 酵母菌是什么| 一个提手一个京念什么| 微不足道是什么意思| 什么人容易得阿尔兹海默症| 下眼睑红肿是什么原因| 腹胀挂什么科| 植物是什么| 不割包皮有什么影响吗| 生长纹是什么原因| 心内科是看什么病的| 捡到金子预示着什么| 亚麻籽吃了有什么好处| 冰恋是什么意思| nsa是什么意思| 什么是梨形身材| 晚上十二点是什么时辰| 牙龈发炎是什么原因引起的| 什么牌子的冰箱最好| 鼻鼽病是什么意思| 总蛋白偏低是什么原因| 软著有什么用| 牛油果核有什么用| 拿什么东西不用手| fast什么意思| 什么得什么| 明眸皓齿是什么意思| 砂舞是什么意思| 全套是什么意思| 公务员国考和省考有什么区别| 冬虫夏草生长在什么地方| 钙片什么时候吃效果最好| 批捕意味着什么| 亲吻是什么感觉| phonics是什么意思| 早上吃鸡蛋有什么好处| 尿尿疼是什么原因| 人体出汗多是什么原因| 砭石是什么东西| 肉蒲团是什么| 5月22号是什么星座| 朔望月是什么意思| 常吃阿司匹林有什么副作用| 木薯粉是什么东西| 脚气是什么菌引起的| 心悸是什么原因造成的呢| 炖羊排放什么调料| 孩子咳嗽能吃什么水果| 夫复何求什么意思| 手指麻木是什么病的前兆| 农历五月是什么星座| 洗面奶什么时候用最好| 心绞痛是什么病| 12月是什么座| 11月14日什么星座| 断崖式是什么意思| 性功能下降吃什么药| 狐媚子是什么意思| 阿斯伯格综合征是什么| 高就是什么意思| 普渡众生是什么意思| 吃维生素b6有什么好处和副作用| 1938年属什么生肖属相| 冻豆腐炖什么好吃| 什么是断桥铝| bn是什么意思| 呦西是什么意思| 什么是环切手术| 试管婴儿什么价格| 去医院看嘴唇挂什么科| dumpling是什么意思| 1901年属什么生肖| cea是什么意思| 为什么体重一直下降| 腿浮肿是什么原因| 是什么歌曲| 今天是什么日子啊| 湿疹擦什么药膏| 螺内酯片治什么病| 小蜘蛛吃什么| 乐加是什么药| 太平猴魁属于什么茶类| 自然流产是什么症状| n t是什么检查| 镉是什么东西| 跳楼是什么感觉| 镜面人是什么意思| 小赤佬是什么意思| 肾炎吃什么药| 儿童拉肚子吃什么药| 吃多种维生素有什么好处和坏处| 眼睛干涩有异物感用什么眼药水| 粘液阳性是什么意思| nikon是什么牌子| 嘴唇上起泡是什么原因| 蚂蚱喜欢吃什么| 检测怀孕最准确的方法是什么| 青春期什么时候结束| 从未是什么意思| 韩红是什么军衔| 鲤鱼打挺是什么意思| 发霉是什么菌| 右肩膀痛是什么原因| 痛风不能喝什么饮料| 1月13日是什么星座| 总胆固醇偏高是什么原因| 夏对什么| 重庆市长什么级别| 爱理不理是什么意思| 孕妇可以吃什么感冒药| 母亲节是什么时候| 辐照食品什么意思| k14是什么金| 一个虫一个合读什么| 关节间隙变窄什么意思| 256排ct能检查什么病| 小乌龟吃什么| 痰湿体质吃什么中成药| 吃东西容易呛到是什么原因| 人怕冷是什么原因引起的| 慢性胃炎可以吃什么水果| 钮祜禄氏是什么旗| 石蜡是什么| 养肝护肝吃什么食物| 全麦是什么意思| 为什么不建议打卧蚕呢| 前纵韧带钙化是什么意思| 痰核流注什么意思| 得意忘形是什么意思| 百度
Skip to content

schmich/instascan

Repository files navigation

Instascan Instascan

Real-time webcam-driven HTML5 QR code scanner. Try the live demo.

Installing

Note: Chrome requires HTTPS when using the WebRTC API. Any pages using this library should be served over HTTPS.

NPM

npm install --save instascan

const Instascan = require('instascan');

Bower

Pending. Drop a note if you need Bower support.

Minified

Copy instascan.min.js from the releases page and load with:

<script type="text/javascript" src="instascan.min.js"></script>

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Instascan</title>
    <script type="text/javascript" src="instascan.min.js"></script>
  </head>
  <body>
    <video id="preview"></video>
    <script type="text/javascript">
      let scanner = new Instascan.Scanner({ video: document.getElementById('preview') });
      scanner.addListener('scan', function (content) {
        console.log(content);
      });
      Instascan.Camera.getCameras().then(function (cameras) {
        if (cameras.length > 0) {
          scanner.start(cameras[0]);
        } else {
          console.error('No cameras found.');
        }
      }).catch(function (e) {
        console.error(e);
      });
    </script>
  </body>
</html>

API

let scanner = new Instascan.Scanner(opts)

Create a new scanner with options:

let opts = {
  // Whether to scan continuously for QR codes. If false, use scanner.scan() to manually scan.
  // If true, the scanner emits the "scan" event when a QR code is scanned. Default true.
  continuous: true,
  
  // The HTML element to use for the camera's video preview. Must be a <video> element.
  // When the camera is active, this element will have the "active" CSS class, otherwise,
  // it will have the "inactive" class. By default, an invisible element will be created to
  // host the video.
  video: document.getElementById('preview'),
  
  // Whether to horizontally mirror the video preview. This is helpful when trying to
  // scan a QR code with a user-facing camera. Default true.
  mirror: true,
  
  // Whether to include the scanned image data as part of the scan result. See the "scan" event
  // for image format details. Default false.
  captureImage: false,
  
  // Only applies to continuous mode. Whether to actively scan when the tab is not active.
  // When false, this reduces CPU usage when the tab is not active. Default true.
  backgroundScan: true,
  
  // Only applies to continuous mode. The period, in milliseconds, before the same QR code
  // will be recognized in succession. Default 5000 (5 seconds).
  refractoryPeriod: 5000,
  
  // Only applies to continuous mode. The period, in rendered frames, between scans. A lower scan period
  // increases CPU usage but makes scan response faster. Default 1 (i.e. analyze every frame).
  scanPeriod: 1
};

scanner.start(camera)

  • Activate camera and start scanning using it as the source. Returns promise.
  • This must be called in order to use scanner.scan or receive scan events.
  • camera: Instance of Instascan.Camera from Instascan.Camera.getCameras.
  • .then(function () { ... }): called when camera is active and scanning has started.
  • .catch(function (err) { ... })
    • Called when an error occurs trying to initialize the camera for scanning.
    • err: An Instascan.MediaError in the case of a known getUserMedia failure (see error types).

scanner.stop()

  • Stop scanning and deactivate the camera. Returns promise.
  • .then(function () { ... }): called when camera and scanning have stopped.

let result = scanner.scan()

  • Scan video immediately for a QR code.
  • QR codes recognized with this method are not emitted via the scan event.
  • If no QR code is detected, result is null.
  • result.content: Scanned content decoded from the QR code.
  • result.image: Undefined if scanner.captureImage is false, otherwise, see the scan event for format.

scanner.addListener('scan', callback)

  • Emitted when a QR code is scanned using the camera in continuous mode (see scanner.continuous).
  • callback: function (content, image)
    • content: Scanned content decoded from the QR code.
    • image: null if scanner.captureImage is false, otherwise, a base64-encoded WebP-compressed data URI of the camera frame used to decode the QR code.

scanner.addListener('active', callback)

  • Emitted when the scanner becomes active as the result of scanner.start or the tab gaining focus.
  • If opts.video element was specified, it will have the active CSS class.
  • callback: function ()

scanner.addListener('inactive', callback)

  • Emitted when the scanner becomes inactive as the result of scanner.stop or the tab losing focus.
  • If opts.video element was specified, it will have the inactive CSS class.
  • callback: function ()

Instascan.Camera.getCameras()

  • Enumerate available video devices. Returns promise.
  • .then(function (cameras) { ... })
    • Called when cameras are available.
    • cameras: Array of Instascan.Camera instances available for use.
  • .catch(function (err) { ... })
    • Called when an error occurs while getting cameras.
    • err: An Instascan.MediaError in the case of a known getUserMedia failure (see error types).

camera.id

  • Unique camera ID provided by the browser.
  • These IDs are stable and can be persisted across instances of your application (e.g. in localStorage).

camera.name

  • Camera name, including manufacturer and model
  • e.g. "Microsoft LifeCam HD-3000".

Compatibility

Instascan works on non-iOS platforms in any browser that supports the WebRTC/getUserMedia API, which currently includes Chome, Firefox, Opera, and Edge. IE and Safari are not supported.

Instascan does not work on iOS since Apple does not yet support WebRTC in WebKit and forces other browser vendors (Chrome, Firefox, Opera) to use their implementation of WebKit. Apple is actively working on WebRTC support in WebKit.

Performance

Many factors affect how quickly and reliably Instascan can detect QR codes.

If you control creation of the QR code, consider the following:

  • A larger physical code is better. A 2" square code is better than a 1" square code.
  • Flat, smooth, matte surfaces are better than curved, rough, glossy surfaces.
  • Include a sufficient quiet zone, the white border surrounding QR code. The quiet zone should be at least four times the width of an individual element in your QR code.
  • A simpler code is better. You can use this QR code generator to see how your input affects complexity.
  • For the same length, numeric content is simpler than ASCII content, which is simpler than Unicode content.
  • Shorter content is simpler. If you're encoding a URL, consider using a shortener such as goo.gl or bit.ly.

When scanning, consider the following:

  • QR code orientation doesn't matter.
  • Higher resolution video is better, but is more CPU intensive.
  • Direct, orthogonal scanning is better than scanning at an angle.
  • Blurry video greatly reduces scanner performance.
  • Auto-focus can cause lags in detection as the camera adjusts focus. Consider disabling it or using a fixed-focus camera with the subject positioned at the focal point.
  • Exposure adjustment on cameras can cause lags in detection. Consider disabling it or having a fixed white backdrop.

Example Setup

  • Purpose: To scan QR code stickers on paper cards and plastic bags.
  • Camera: Microsoft LifeCam HD-3000, 720p, fixed focus, around $30 USD.
  • Small support to ensure camera is focused on subject.
  • White paper backdrop to mitigate exposure adjustment.

Setup

Credits

Powered by the Emscripten JavaScript build of the C++ port of the ZXing Java library.

License

Copyright ? 2016 Chris Schmich
MIT License. See LICENSE for details.

嗜酸性肉芽肿是什么病 夏天容易出汗是什么原因 dw手表属于什么档次 炖羊排放什么调料 婆婆过生日送什么礼物好
社保缴费基数什么意思 梦见财神爷是什么预兆 暗物质和暗能量是什么 不造血是什么病 河字五行属什么
捂脸表情什么意思 月亮为什么会发光 人乳头瘤病毒51型阳性是什么意思 焦虑症是什么 床榻是什么意思
举案齐眉是什么意思 死库水是什么意思 118代表什么意思 什么是宾格 二级乙等医院什么档次
锡兵是什么hcv8jop7ns5r.cn 左耳朵嗡嗡响是什么原因引起的hcv8jop0ns0r.cn 沙僧的武器是什么hcv9jop3ns5r.cn 四大天王叫什么名字jasonfriends.com 左室高电压什么意思yanzhenzixun.com
感冒去医院挂什么科hcv8jop9ns9r.cn 为什么很多人不去庐山hcv9jop5ns9r.cn 碎银子是什么茶hcv8jop2ns3r.cn 为什么会有同性恋xinmaowt.com 什么样的大象hcv9jop7ns2r.cn
皮革胃是什么意思hcv8jop0ns1r.cn 爱慕是什么意思hcv8jop6ns9r.cn 冤家是什么意思hcv8jop4ns4r.cn 梧桐树叶像什么hcv8jop4ns8r.cn 天之骄子是什么意思hcv9jop0ns9r.cn
什么方法睡觉快速入睡hcv8jop6ns7r.cn 身不由己是什么生肖hcv8jop3ns5r.cn 花甲之年是什么意思hcv8jop7ns6r.cn 蛇七寸是什么部位hcv8jop7ns7r.cn police是什么品牌hcv8jop4ns9r.cn
百度