information community file
Technical capability
Voice technology
Character recognition
Face and Human Body
Image technology
Language and knowledge
video technique

Household registration book identification

Interface description

It supports all 22 fields of the permanent population registration card in the household register, including the household number, name, relationship with the head of household, gender, place of birth, nationality, date of birth, ID card number, other addresses in the city and county, former name, place of origin, religious belief, height, blood type, education, marital status, military service status, service location, occupation, when and where to move to the city When and where to move to this address, and the registration date.

Support structured identification of 5 fields of the home page in the account book, including the account type, name, number, address and time of the home page.

Online debugging

You can visit Sample Code Center Debug the interface in , you can perform signature verification, view the request content and return results of online calls, and automatically generate sample code.

Request Description

Request Example

HTTP method: POST

Request URL: https://aip.baidubce.com/rest/2.0/ocr/v1/household_register

URL parameter:

parameter value
access_token Access_token obtained through API Key and Secret Key, refer to“ Access Token acquisition

The headers are as follows:

parameter value
Content-Type application/x-www-form-urlencoded

Place the request parameters in the body. The details of the parameters are as follows:

Request Parameters

parameter Required type Optional value range explain
image Or url string - Image data is encoded with urlencode after base64 encoding. The size after base64 encoding and urlencode is required not to exceed 4M, the shortest side is at least 15px, and the longest side is at most 4096px. It supports jpg/jpeg/png/bmp format
url And image string - The image is a complete URL. The URL length does not exceed 1024 bytes. The size of the image corresponding to the URL after base64 encoding does not exceed 4M. The shortest side is at least 15px, and the longest side is at most 4096px. It supports the jpg/jpeg/png/bmp format. When the image field exists, the url field is invalid
Please close the URL anti-theft chain
household_register_side no string subpage/homepage -subpage: Default , Permanent Population Registration Card (member page)
-Homepage: Home page

Request Code Example

Prompt 1 : Before using the sample code, remember to replace the sample token, image address or Base64 information.

Prompt 2 : Some languages depend on classes or libraries. Please check the download address in the code comment.

 curl -i -k ' https://aip.baidubce.com/rest/2.0/ocr/v1/household_register?access_token= [Call the token obtained from the authentication interface] ' --data 'image=[Picture Base64 encoding, UrlEncode required]' -H 'Content-Type:application/x-www-form-urlencoded'
 # encoding:utf-8

 import requests import base64 ''' Household registration book identification ''' request_url =  " https://aip.baidubce.com/rest/2.0/ocr/v1/household_register "
 #Open picture file in binary mode f =  open ( '[Local file]' ,  'rb' ) img = base64 . b64encode ( f . read ( ) ) params =  { "image" : img } access_token =  '[Token obtained by calling the authentication interface]' request_url = request_url +  "?access_token="  + access_token headers =  { 'content-type' :  'application/x-www-form-urlencoded' } response = requests . post ( request_url , data = params , headers = headers )
 if response :
     print  ( response . json ( ) )
 package  com . baidu . ai . aip ;

 import  com . baidu . ai . aip . utils . Base64Util ;
 import  com . baidu . ai . aip . utils . FileUtil ;
 import  com . baidu . ai . aip . utils . HttpUtil ;

 import  java . net . URLEncoder ;

 /** *Household registration book identification */
 public  class  HouseholdRegister  {

     /** *Tool class required in important tip code *FileUtil, Base64Util, HttpUtil, GsonUtils *  https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72 *  https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2 *  https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3 *  https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3 *Download */
     public  static  String  householdRegister ( )  {
         //Request url
         String url =  " https://aip.baidubce.com/rest/2.0/ocr/v1/household_register " ;
         try  {
             //Local file path
             String filePath =  [Local file path] ;
             byte [ ] imgData =  FileUtil . readFileByBytes ( filePath ) ;
             String imgStr =  Base64Util . encode ( imgData ) ;
             String imgParam =  URLEncoder . encode ( imgStr ,  "UTF-8" ) ;

             String param =  "image="  + imgParam ;

             //Note that the purpose here is to simplify the encoding and obtain access_token for each request. The online environment access_token has an expiration time, and the client can cache it and retrieve it after expiration.
             String accessToken =  "[Token obtained by calling the authentication interface]" ;

             String result =  HttpUtil . post ( url , accessToken , param ) ;
             System . out . println ( result ) ;
             return result ;
         }  catch  ( Exception e )  { e . printStackTrace ( ) ;
         }
         return  null ;
     }

     public  static  void  main ( String [ ] args )  {
         HouseholdRegister . householdRegister ( ) ;
     }
 }
 # include  <iostream>
 # include  <curl/curl.h>

 //Download link of libcurl library: https://curl.haxx.se/download.html
 //Download link of jsoncpp library: https://github.com/open-source-parsers/jsoncpp/
 const  static std :: string request_url =  " https://aip.baidubce.com/rest/2.0/ocr/v1/household_register " ;
 static std :: string householdRegister_result ;
 /** *The curl sends the callback function called by the http request. The returned body in json format is parsed in the callback function, and the parsing result is stored in the global static variable *See the libcurl document for @ param parameter definitions *@ return See the libcurl document for the definition of the return value */
 static size_t callback ( void  * ptr , size_t size , size_t nmemb ,  void  * stream )  {
     //The obtained body is stored in ptr and converted to string format first householdRegister_result = std :: string ( ( char  * ) ptr , size * nmemb ) ;
     return size * nmemb ;
 }
 /** *Household registration book identification *@ return If the call is successful, 0 will be returned. If an error occurs, other error codes will be returned */
 int  householdRegister ( std :: string & json_result ,  const std :: string & access_token )  { std :: string url = request_url +  "?access_token="  + access_token ; CURL * curl =  NULL ; CURLcode result_code ;
     int is_success ; curl =  curl_easy_init ( ) ;
     if  ( curl )  {
         curl_easy_setopt ( curl , CURLOPT_URL , url . data ( ) ) ;
         curl_easy_setopt ( curl , CURLOPT_POST ,  one ) ; curl_httppost * post =  NULL ; curl_httppost * last =  NULL ;
         curl_formadd ( & post ,  & last , CURLFORM_COPYNAME ,  "image" , CURLFORM_COPYCONTENTS ,  "【base64_img】" , CURLFORM_END ) ;

         curl_easy_setopt ( curl , CURLOPT_HTTPPOST , post ) ;
         curl_easy_setopt ( curl , CURLOPT_WRITEFUNCTION , callback ) ; result_code =  curl_easy_perform ( curl ) ;
         if  ( result_code != CURLE_OK )  {
             fprintf ( stderr ,  "curl_easy_perform() failed: %s\n" ,
                     curl_easy_strerror ( result_code ) ) ; is_success =  one ;
             return is_success ;
         } json_result = householdRegister_result ;
         curl_easy_cleanup ( curl ) ; is_success =  zero ;
     }  else  {
         fprintf ( stderr ,  "curl_easy_init() failed." ) ; is_success =  one ;
     }
     return is_success ;
 }
 <? php
 /** *Initiate http post requests (REST APIs) and obtain the results of REST requests * @param string $url * @param string $param * @return - http response body if succeeds, else false. */
 function  request_post ( $url  =  '' ,  $param  =  '' )
 {
     if  ( empty ( $url )  ||  empty ( $param ) )  {
         return  false ;
     }

     $postUrl  =  $url ;
     $curlPost  =  $param ;
     //Initialize curl
     $curl  =  curl_init ( ) ;
     curl_setopt ( $curl ,  CURLOPT_URL ,  $postUrl ) ;
     curl_setopt ( $curl ,  CURLOPT_HEADER ,  zero ) ;
     //The result is required to be a string and output to the screen
     curl_setopt ( $curl ,  CURLOPT_RETURNTRANSFER ,  one ) ;
     curl_setopt ( $curl ,  CURLOPT_SSL_VERIFYPEER ,  false ) ;
     //Post submission method
     curl_setopt ( $curl ,  CURLOPT_POST ,  one ) ;
     curl_setopt ( $curl ,  CURLOPT_POSTFIELDS ,  $curlPost ) ;
     //Run curl
     $data  =  curl_exec ( $curl ) ;
     curl_close ( $curl ) ;

     return  $data ;
 }

 $token  =  '[Token obtained by calling the authentication interface]' ;
 $url  =  ' https://aip.baidubce.com/rest/2.0/ocr/v1/household_register?access_token= '  .  $token ;
 $img  =  file_get_contents ( '[Local file path]' ) ;
 $img  =  base64_encode ( $img ) ;
 $bodys  =  array (
     'image'  = >  $img
 ) ;
 $res  =  request_post ( $url ,  $bodys ) ;

 var_dump ( $res ) ;
 using System ;
 using System . IO ;
 using System . Net ;
 using System . Text ;
 using System . Web ;

 namespace com . baidu . ai {
     public  class  HouseholdRegister
     {
         //Household registration book identification
         public  static  string  householdRegister ( )
         {
             string token =  "[Token obtained by calling the authentication interface]" ;
             string host =  " https://aip.baidubce.com/rest/2.0/ocr/v1/household_register?access_token= "  + token ;
             Encoding encoding = Encoding . Default ;
             HttpWebRequest request =  ( HttpWebRequest ) WebRequest . Create ( host ) ; request . Method =  "post" ; request . KeepAlive =  true ;
             //Base64 encoding of pictures
             string base64 =  getFileBase64 ( [Local picture file] ) ;
             String str =  "image="  + HttpUtility . UrlEncode ( base64 ) ;
             byte [ ] buffer = encoding . GetBytes ( str ) ; request . ContentLength = buffer . Length ; request . GetRequestStream ( ) . Write ( buffer ,  zero , buffer . Length ) ;
             HttpWebResponse response =  ( HttpWebResponse ) request . GetResponse ( ) ;
             StreamReader reader =  new  StreamReader ( response . GetResponseStream ( ) , Encoding . Default ) ;
             string result = reader . ReadToEnd ( ) ; Console . WriteLine ( "Household Register Identification:" ) ; Console . WriteLine ( result ) ;
             return result ;
         }

         public  static  String  getFileBase64 ( String fileName )  {
             FileStream filestream =  new  FileStream ( fileName , FileMode . Open ) ;
             byte [ ] arr =  new  byte [ filestream . Length ] ; filestream . Read ( arr ,  zero ,  ( int ) filestream . Length ) ;
             string baser64 = Convert . ToBase64String ( arr ) ; filestream . Close ( ) ;
             return baser64 ;
         }
     }
 }

Return description

Return parameters
Permanent Population Registration Card (member page)

field Required type explain
log_id yes uint64 Unique log ID for problem location
words_result_num yes int The number of recognition results, representing the number of words_result elements
words_result yes object{} Identification results
+ Name yes object{} full name
++ words yes string The specific content of the field to which it belongs. The following fields all contain this element
+ Relationship yes object{} Head of household or relationship with head of household
+ Sex yes object{} Gender
+ BirthAddress yes object{} one's native heath
+ Nation yes object{} nation
+ Birthday yes object{} birthday
+ CardNo yes object{} ID number
+ HouseholdNum yes object{} Account No
+ FormerName yes object{} Name used before
+ Hometown yes object{} Native place
+ OtherAddress yes object{} Other address in the city (county)
+ Belief yes object{} religious belief
+ Height yes object{} height
+ BloodType yes object{} blood type
+ Education yes object{} degree of education
+ MaritalStatus yes object{} marital status
+ VeteranStatus yes object{} Military service status
+ WorkAddress yes object{} Service premises
+ Career yes object{} occupation
+ WWToCity yes object{} When and where moved to this city (county)
+ WWHere yes object{} When and where to move to this address
+ Date yes object{} Registration date

Home page

field Required type explain
log_id yes uint64 Unique log ID for problem location
words_result_num yes int The number of recognition results, representing the number of words_result elements
direction yes int32 Image direction. This parameter is returned when the image is rotated.
-- 1: Undefined,
-0: Forward,
-1: 90 degrees counterclockwise,
-2: 180 degrees counterclockwise,
-3: 270 degrees counterclockwise
words_result yes object{} Identification results
+ HouseholdType yes object{} Household type
++ words yes string The specific content of the field to which it belongs. The following fields all contain this element
+ HouseholderName yes object{} Name of householder
+ HouseholdNum yes object{} Account No
+ Address yes object{} address
+ IssueDate yes object{} Date of issue

Return to Example

 {
	 "words_result" :  {
		 "Nation" :  {
			 "words" :  "Han nationality"
		 } ,
		 "Sex" :  {
			 "words" :  Female
		 } ,
		 "Birthday" :  {
			 "words" :  "July 27, 1994"
		 } ,
		 "Date" :  {
			 "words" :  "July 27, 2017"
		 } ,
		 "BirthAddress" :  {
			 "words" :  "Sichuan Province"
		 } ,
		 "Name" :  {
			 "words" :  Wang Yan
		 } ,
         "FormerName	" :  {
			 "words" :  "Wang Jia"
		 } ,
		 "HouseholdNum" :  {
			 "words" :  "000007670"
		 } ,
		 "WWToCity" :  {
			 "words" :  "Youjiuju"
		 } ,
		 "WWHere" :  {
			 "words" :  "Moved here due to birth on July 27, 1994"
		 } ,
		 "CardNo" :  {
			 "words" :  "112102199407273123"
		 } ,
		 "Education" :  {
			 "words" :  "Junior high school graduation"
		 } ,
		 "Relationship" :  {
			 "words" :  "Only child"
		 } ,
		 "Height" :  {
			 "words" :  170 cm
		 } ,
         "Career" :  {
			 "words" :  None
		 } ,
		 "WorkAddress" :  {
			 "words" :  None
		 } ,
		 "Hometown" :  {
			 "words" :  "Sichuan Province"
		 }
         "OtherAddress" :  {
			 "words" :  "Leshan City, Sichuan Province"
		 }
         "Belief" :  {
			 "words" :  Buddhism
		 }
         "BloodType" :  {
			 "words" :  Type A
		 }
          "MaritalStatus" :  {
			 "words" :  "Unmarried"
		 }
         "VeteranStatus" :  {
			 "words" :  None
		 }
	 } ,
	 "log_id" :  "1407164137607266304" ,
	 "words_result_num" :  twenty-two
 }
Previous
Social Security Card Identification
Next
Identification of birth medical certificate