# ID Card Testing

VisionKit From the base library 3.3.0 version Then start supporting.

ID Card Testing Ability to function in conjunction with Other VisionKit ability Parallel capability interface.

The capability, which is generally used by users to carry out Identification card identification or ID Card Cutting Development of such functions.

# Definition of method

ID card detection is currently supported only through Visual pattern, that is, enter a static picture to identify the ID card, and return the corresponding information of the ID card.

Can be configured by getAffineImg , determines whether each recognition returns ID Zone Clipping Matrix

# Input ID Picture Requirements

Picture of the ID card entered, try to Shot at a normal angleThe different angles brought Perspective effect, will affect the identification of the Accuracy

# Visual mode interface

First you need to create VKSession Of the configuration is then passed through the VKSession.start start-up VKSession Instance.

Open VKSession, and add the return of the corresponding identity card information listening event, sample code:

// VKSession To configure
const session = wx.createVKSession({
    track: {
        IDCard: {
            mode: 2 // Photo mode
        }
    },
    version: 'v1',
})

// VKSession start
session.start(err => {

  // In Static Picture Estimation mode, each tone detectIDCard The interface will trigger once updateAnchors event
  session.on('updateAnchors', anchors => {
      // Processing the returned ID card information
      if (anchors && anchors[0]) {
          // Existence of an array, proving the existence of ID card information
          const anchor = anchors[0]

          // Identifying information
          const isComplete = anchor.isComplete // The identity card is complete
          const label = anchor.label // ID Card Face Information (0 Photo Face / 1 Coat of arms )
          const orientation = anchor.orientation // ID card towards (0 Facing up 1 Facing down 2 Facing down 3 Morning left) 
          const box = anchor.box // ID Card Frame Point Group (0 Left upper point  1 Upper right point  2 Lower Right Point 3 Lower Left Point)

          // Clipping Information, Interface getAffineImg for true It will return.
          const affineImgWidth = anchor.affineImgWidth
          const affineImgHeight = anchor.affineImgHeight
          const affineMat = anchor.affineMat

          // There is cropping information, can be combined with the original picture to get the cut ID card picture
          if (affineImgWidth && affineImgHeight && affineMat) {
            /*
              * affineMat 3x3 affine transformation matrix, row main order
              *  [0 1 2
              *   3 4 5
              *   6 7 8]
              */
            /*
              * canvas 2d setTransform
              * setTransform(a, b, c, d, e, f)
              *  [a c e
              *   b d f
              *   0 0 1]
              */
             // Can use off screen Canvas2D, combined with the original picture and cutting matrix, specific body photo cutting.
          }
      }

  })
  // Picture does not identify the ID card, will trigger a removeAnchors
  session.on('removeAnchors',  anchors => {
      console.log("no i.d.")
  })
})

Calling ID Card Recognition, Example Code:


// Calling the specific ID card picture recognition interface
session.detectIDCard({
    // Identify the picture of the ID card ArrayBuffer,Uint8ClampedArray,RGBA 
    // For example, by Canvas (2D) of context.getImageData Obtain
    frameBuffer: imgDataBuffer,
    // Pass in the original width of the recognition picture
    width: imgOriginWidth,
    // Pass in the original height of the recognition picture
    height: imgOriginHeight,
    // Whether to get crop picture information
    getAffineImg: true,
})
// After the call, after the identification is processed
// Recognition success will trigger updateAnchors Callback, processing failure will trigger removeAnchors Callback

# Output Dxplaination

anchor information

struct anchor
{
  isComplete,  // The identity card is complete
  label,       // ID Card Face Information (0 Photo Face / 1 Coat of arms )
  orientation, // ID card towards (0 Facing up 1 Facing down 2 Facing down 3 Morning left) 
  box,         // ID Card Frame Point Group (0 Left upper point  1 Upper right point  2 Lower Right Point 3 Lower Left Point)
  /* ID Card Cutting Information
   * getAffineImg for true Time to return */
  affineImgWidth,   // ID Card Cutting Width
  affineImgHeight,  // ID Crop Area Height
  affineMat,        // ID card clipping matrix
}

# ID Card Frame Point Group box

Length is 4 An array of, representing The ID card is located in the original picture, the box coordinates point position.

Array<Point>(8) box

Each array element is structured as:

struct Point { x, y }

# ID card clipping matrix affineMat

Length is 9 Represents the line main order of an array of of 3x3 affine transformation matrix. Can be combined Canvas (2D) And the original image for specific ID card picture cutting.

# Program Examples

# ID Photo Identification Example

Small Program Example of interface - VisionKit Visual Capabilities - Photo ID Card Identification

Open Source Address:[Photo ID Card Identification](https://github.com/WeChat mini-program /miniprogram-demo/tree/master/miniprogram/packageAPI/pages/ar/photo-idcard-detect)