@@ -11,6 +11,7 @@ import (
1111 "hash/crc64"
1212 "io"
1313 "net/http"
14+ "net/url"
1415 "os"
1516 "strconv"
1617)
@@ -1261,7 +1262,6 @@ func (s *CIService) DeleteStyle(ctx context.Context, opt *DeleteStyleOptions) (*
12611262 return resp , err
12621263}
12631264
1264- // ImageQualityResult TODO
12651265type ImageQualityResult struct {
12661266 XMLName xml.Name `xml:"Response"`
12671267 LongImage bool `xml:"LongImage,omitempty"`
@@ -1287,7 +1287,6 @@ func (s *CIService) ImageQuality(ctx context.Context, obj string) (*ImageQuality
12871287 return & res , resp , err
12881288}
12891289
1290- // OcrRecognitionOptions TODO
12911290type OcrRecognitionOptions struct {
12921291 Type string `url:"type,omitempty"`
12931292 LanguageType string `url:"language-type,omitempty"`
@@ -1297,7 +1296,6 @@ type OcrRecognitionOptions struct {
12971296 EnableWordPolygon bool `url:"enable-word-polygon,omitempty"`
12981297}
12991298
1300- // OcrRecognitionResult TODO
13011299type OcrRecognitionResult struct {
13021300 XMLName xml.Name `xml:"Response"`
13031301 TextDetections []TextDetections `xml:"TextDetections,omitempty"`
@@ -1307,7 +1305,6 @@ type OcrRecognitionResult struct {
13071305 RequestId string `xml:"RequestId,omitempty"`
13081306}
13091307
1310- // TextDetections TODO
13111308type TextDetections struct {
13121309 DetectedText string `xml:"DetectedText,omitempty"`
13131310 Confidence int `xml:"Confidence,omitempty"`
@@ -1317,7 +1314,6 @@ type TextDetections struct {
13171314 WordPolygon []WordPolygon `xml:"WordPolygon,omitempty"`
13181315}
13191316
1320- // Polygon TODO
13211317type Polygon struct {
13221318 X int `xml:"X,omitempty"`
13231319 Y int `xml:"Y,omitempty"`
@@ -1331,24 +1327,21 @@ type ItemPolygon struct {
13311327 Height int `xml:"Height,omitempty"`
13321328}
13331329
1334- // Words TODO
13351330type Words struct {
1336- Confidence int `xml:"Confidence,omitempty"`
1337- Character string `xml:"Character,omitempty"`
1338- WordCoordPoint WordCoordPoint `xml:"WordCoordPoint,omitempty"`
1331+ Confidence int `xml:"Confidence,omitempty"`
1332+ Character string `xml:"Character,omitempty"`
1333+ WordCoordPoint * WordCoordPoint `xml:"WordCoordPoint,omitempty"`
13391334}
13401335
1341- // WordCoordPoint TODO
13421336type WordCoordPoint struct {
13431337 WordCoordinate []Polygon `xml:"WordCoordinate,omitempty"`
13441338}
13451339
1346- // WordPolygon TODO
13471340type WordPolygon struct {
1348- LeftTop Polygon `xml:"LeftTop,omitempty"`
1349- RightTop Polygon `xml:"RightTop,omitempty"`
1350- RightBottom Polygon `xml:"RightBottom,omitempty"`
1351- LeftBottom Polygon `xml:"LeftBottom,omitempty"`
1341+ LeftTop * Polygon `xml:"LeftTop,omitempty"`
1342+ RightTop * Polygon `xml:"RightTop,omitempty"`
1343+ RightBottom * Polygon `xml:"RightBottom,omitempty"`
1344+ LeftBottom * Polygon `xml:"LeftBottom,omitempty"`
13521345}
13531346
13541347// OcrRecognition OCR通用文字识别
@@ -1365,14 +1358,12 @@ func (s *CIService) OcrRecognition(ctx context.Context, obj string, opt *OcrReco
13651358 return & res , resp , err
13661359}
13671360
1368- // DetectCarResult TODO
13691361type DetectCarResult struct {
13701362 XMLName xml.Name `xml:"Response"`
13711363 RequestId string `xml:"RequestId,omitempty"`
13721364 CarTags []CarTags `xml:"CarTags,omitempty"`
13731365}
13741366
1375- // CarTags TODO
13761367type CarTags struct {
13771368 Serial string `xml:"Serial,omitempty"`
13781369 Brand string `xml:"Brand,omitempty"`
@@ -1384,21 +1375,18 @@ type CarTags struct {
13841375 PlateContent []PlateContent `xml:"PlateContent,omitempty"`
13851376}
13861377
1387- // CarLocation TODO
13881378type CarLocation struct {
13891379 X int `xml:"X,omitempty"`
13901380 Y int `xml:"Y,omitempty"`
13911381}
13921382
1393- // PlateContent TODO
13941383type PlateContent struct {
1395- Plate string `xml:"Plate,omitempty"`
1396- Color string `xml:"Color,omitempty"`
1397- Type string `xml:"Type,omitempty"`
1398- PlateLocation PlateLocation `xml:"PlateLocation,omitempty"`
1384+ Plate string `xml:"Plate,omitempty"`
1385+ Color string `xml:"Color,omitempty"`
1386+ Type string `xml:"Type,omitempty"`
1387+ PlateLocation * PlateLocation `xml:"PlateLocation,omitempty"`
13991388}
14001389
1401- // PlateLocation TODO
14021390type PlateLocation struct {
14031391 X int `xml:"X,omitempty"`
14041392 Y int `xml:"Y,omitempty"`
@@ -1562,16 +1550,13 @@ type DetectFaceResult struct {
15621550 FaceInfos []FaceInfos `xml:"FaceInfos,omitempty"`
15631551}
15641552
1565-
1566- // FaceInfos TODO
15671553type FaceInfos struct {
15681554 X int `xml:"X,omitempty"`
15691555 Y int `xml:"Y,omitempty"`
15701556 Width int `xml:"Width,omitempty"`
15711557 Height int `xml:"Height,omitempty"`
15721558}
15731559
1574- // DetectFace TODO
15751560func (s * CIService ) DetectFace (ctx context.Context , obj string , opt * DetectFaceOptions ) (* DetectFaceResult , * Response , error ) {
15761561 var res DetectFaceResult
15771562 sendOpt := & sendOptions {
@@ -1585,7 +1570,6 @@ func (s *CIService) DetectFace(ctx context.Context, obj string, opt *DetectFaceO
15851570 return & res , resp , err
15861571}
15871572
1588- // FaceEffectOptions TODO
15891573type FaceEffectOptions struct {
15901574 Type string `url:"type,omitempty"`
15911575 Whitening int `url:"whitening,omitempty"`
@@ -1596,14 +1580,12 @@ type FaceEffectOptions struct {
15961580 Age int `url:"age,omitempty"`
15971581}
15981582
1599- // FaceEffectResult TODO
16001583type FaceEffectResult struct {
16011584 XMLName xml.Name `xml:"Response"`
16021585 ResultImage string `xml:"ResultImage,omitempty"`
16031586 ResultMask string `xml:"ResultMask,omitempty"`
16041587}
16051588
1606- // FaceEffect TODO
16071589func (s * CIService ) FaceEffect (ctx context.Context , obj string , opt * FaceEffectOptions ) (* FaceEffectResult , * Response , error ) {
16081590 var res FaceEffectResult
16091591 sendOpt := & sendOptions {
@@ -1616,3 +1598,237 @@ func (s *CIService) FaceEffect(ctx context.Context, obj string, opt *FaceEffectO
16161598 resp , err := s .client .send (ctx , sendOpt )
16171599 return & res , resp , err
16181600}
1601+
1602+ type IdCardOCROptions struct {
1603+ CardSide string `url:"CardSide,omitempty"`
1604+ Config * IdCardOCROptionsConfig `url:"Config,omitempty"`
1605+ }
1606+
1607+ type IdCardOCROptionsConfig struct {
1608+ CropIdCard bool `json:"CropIdCard,omitempty"`
1609+ CropPortrait bool `json:"CropPortrait,omitempty"`
1610+ CopyWarn bool `json:"CopyWarn,omitempty"`
1611+ BorderCheckWarn bool `json:"BorderCheckWarn,omitempty"`
1612+ ReshootWarn bool `json:"ReshootWarn,omitempty"`
1613+ DetectPsWarn bool `json:"DetectPsWarn,omitempty"`
1614+ TempIdWarn bool `json:"TempIdWarn,omitempty"`
1615+ InvalidDateWarn bool `json:"InvalidDateWarn,omitempty"`
1616+ Quality bool `json:"Quality,omitempty"`
1617+ MultiCardDetect bool `json:"MultiCardDetect,omitempty"`
1618+ }
1619+
1620+ func (c * IdCardOCROptionsConfig ) EncodeValues (key string , v * url.Values ) error {
1621+ config , err := json .Marshal (c )
1622+ if err != nil {
1623+ return err
1624+ }
1625+ v .Add ("Config" , string (config ))
1626+
1627+ return nil
1628+ }
1629+
1630+ type IdCardOCRResult struct {
1631+ XMLName xml.Name `xml:"Response"`
1632+ IdInfo * IdCardInfo `xml:"IdInfo,omitempty"`
1633+ AdvancedInfo * IdCardAdvancedInfo `xml:"AdvancedInfo,omitempty"`
1634+ }
1635+
1636+ type IdCardInfo struct {
1637+ Name string `xml:"Name,omitempty"`
1638+ Sex string `xml:"Sex,omitempty"`
1639+ Nation string `xml:"Nation,omitempty"`
1640+ Birth string `xml:"Birth,omitempty"`
1641+ Address string `xml:"Address,omitempty"`
1642+ IdNum string `xml:"IdNum,omitempty"`
1643+ Authority string `xml:"Authority,omitempty"`
1644+ ValidDate string `xml:"ValidDate,omitempty"`
1645+ }
1646+
1647+ type IdCardAdvancedInfo struct {
1648+ IdCard string `xml:"IdCard,omitempty"`
1649+ Portrait string `xml:"Portrait,omitempty"`
1650+ Quality string `xml:"Quality,omitempty"`
1651+ BorderCodeValue string `xml:"BorderCodeValue,omitempty"`
1652+ WarnInfos []string `xml:"WarnInfos,omitempty"`
1653+ }
1654+
1655+ func (s * CIService ) IdCardOCRWhenCloud (ctx context.Context , obj string , query * IdCardOCROptions ) (* IdCardOCRResult , * Response , error ) {
1656+ var res IdCardOCRResult
1657+ sendOpt := & sendOptions {
1658+ baseURL : s .client .BaseURL .BucketURL ,
1659+ method : http .MethodGet ,
1660+ uri : "/" + encodeURIComponent (obj ) + "?ci-process=IDCardOCR" ,
1661+ optQuery : query ,
1662+ result : & res ,
1663+ }
1664+ resp , err := s .client .send (ctx , sendOpt )
1665+ return & res , resp , err
1666+ }
1667+
1668+ func (s * CIService ) IdCardOCRWhenUpload (ctx context.Context , obj , filePath string , query * IdCardOCROptions , header * ObjectPutOptions ) (* IdCardOCRResult , * Response , error ) {
1669+ fd , err := os .Open (filePath )
1670+ if err != nil {
1671+ return nil , nil , err
1672+ }
1673+ defer fd .Close ()
1674+
1675+ if err := CheckReaderLen (fd ); err != nil {
1676+ return nil , nil , err
1677+ }
1678+ opt := CloneObjectPutOptions (header )
1679+ totalBytes , err := GetReaderLen (fd )
1680+ if err != nil && opt != nil && opt .Listener != nil {
1681+ if opt .ContentLength == 0 {
1682+ return nil , nil , err
1683+ }
1684+ totalBytes = opt .ContentLength
1685+ }
1686+ if err == nil {
1687+ // 与 go http 保持一致, 非bytes.Buffer/bytes.Reader/strings.Reader由用户指定ContentLength, 或使用 Chunk 上传
1688+ // if opt != nil && opt.ContentLength == 0 && IsLenReader(r) {
1689+ // opt.ContentLength = totalBytes
1690+ // }
1691+ // lilang : 2022-07-04
1692+ // 图片cgi不设置content-length的话,读不到body。图片处理cgi暂时不支持chunked,后面会修复。
1693+ if opt != nil && opt .ContentLength == 0 {
1694+ opt .ContentLength = totalBytes
1695+ }
1696+
1697+ }
1698+ reader := TeeReader (fd , nil , totalBytes , nil )
1699+ if s .client .Conf .EnableCRC {
1700+ reader .writer = crc64 .New (crc64 .MakeTable (crc64 .ECMA ))
1701+ }
1702+ if opt != nil && opt .Listener != nil {
1703+ reader .listener = opt .Listener
1704+ }
1705+
1706+ var res IdCardOCRResult
1707+ sendOpt := sendOptions {
1708+ baseURL : s .client .BaseURL .BucketURL ,
1709+ uri : "/" + encodeURIComponent (obj ) + "?ci-process=IDCardOCR" ,
1710+ method : http .MethodPut ,
1711+ optQuery : query ,
1712+ body : reader ,
1713+ optHeader : opt ,
1714+ result : & res ,
1715+ }
1716+ resp , err := s .client .send (ctx , & sendOpt )
1717+
1718+ return & res , resp , err
1719+ }
1720+
1721+ type GetLiveCodeResult struct {
1722+ XMLName xml.Name `xml:"Response"`
1723+ LiveCode string `xml:"LiveCode,omitempty"`
1724+ }
1725+
1726+ func (s * CIService ) GetLiveCode (ctx context.Context ) (* GetLiveCodeResult , * Response , error ) {
1727+ var res GetLiveCodeResult
1728+ sendOpt := & sendOptions {
1729+ baseURL : s .client .BaseURL .BucketURL ,
1730+ method : http .MethodGet ,
1731+ uri : "/?ci-process=GetLiveCode" ,
1732+ result : & res ,
1733+ }
1734+ resp , err := s .client .send (ctx , sendOpt )
1735+ return & res , resp , err
1736+ }
1737+
1738+ type GetActionSequenceResult struct {
1739+ XMLName xml.Name `xml:"Response"`
1740+ ActionSequence string `xml:"ActionSequence,omitempty"`
1741+ }
1742+
1743+ func (s * CIService ) GetActionSequence (ctx context.Context ) (* GetActionSequenceResult , * Response , error ) {
1744+ var res GetActionSequenceResult
1745+ sendOpt := & sendOptions {
1746+ baseURL : s .client .BaseURL .BucketURL ,
1747+ method : http .MethodGet ,
1748+ uri : "/?ci-process=GetActionSequence" ,
1749+ result : & res ,
1750+ }
1751+ resp , err := s .client .send (ctx , sendOpt )
1752+ return & res , resp , err
1753+ }
1754+
1755+ type LivenessRecognitionOptions struct {
1756+ IdCard string `url:"IdCard,omitempty"`
1757+ Name string `url:"Name,omitempty"`
1758+ LivenessType string `url:"LivenessType,omitempty"`
1759+ ValidateData string `url:"ValidateData,omitempty"`
1760+ BestFrameNum int `url:"BestFrameNum,omitempty"`
1761+ }
1762+
1763+ type LivenessRecognitionResult struct {
1764+ XMLName xml.Name `xml:"Response"`
1765+ BestFrameBase64 string `xml:"BestFrameBase64,omitempty"`
1766+ Sim float64 `xml:"Sim,omitempty"`
1767+ BestFrameList []string `xml:"BestFrameList,omitempty"`
1768+ }
1769+
1770+ func (s * CIService ) LivenessRecognitionWhenCloud (ctx context.Context , obj string , query * LivenessRecognitionOptions ) (* LivenessRecognitionResult , * Response , error ) {
1771+ var res LivenessRecognitionResult
1772+ sendOpt := & sendOptions {
1773+ baseURL : s .client .BaseURL .BucketURL ,
1774+ method : http .MethodGet ,
1775+ uri : "/" + encodeURIComponent (obj ) + "?ci-process=LivenessRecognition" ,
1776+ optQuery : query ,
1777+ result : & res ,
1778+ }
1779+ resp , err := s .client .send (ctx , sendOpt )
1780+ return & res , resp , err
1781+ }
1782+
1783+ func (s * CIService ) LivenessRecognitionWhenUpload (ctx context.Context , obj , filePath string , query * LivenessRecognitionOptions , header * ObjectPutOptions ) (* LivenessRecognitionResult , * Response , error ) {
1784+ fd , err := os .Open (filePath )
1785+ if err != nil {
1786+ return nil , nil , err
1787+ }
1788+ defer fd .Close ()
1789+
1790+ if err := CheckReaderLen (fd ); err != nil {
1791+ return nil , nil , err
1792+ }
1793+ opt := CloneObjectPutOptions (header )
1794+ totalBytes , err := GetReaderLen (fd )
1795+ if err != nil && opt != nil && opt .Listener != nil {
1796+ if opt .ContentLength == 0 {
1797+ return nil , nil , err
1798+ }
1799+ totalBytes = opt .ContentLength
1800+ }
1801+ if err == nil {
1802+ // 与 go http 保持一致, 非bytes.Buffer/bytes.Reader/strings.Reader由用户指定ContentLength, 或使用 Chunk 上传
1803+ // if opt != nil && opt.ContentLength == 0 && IsLenReader(r) {
1804+ // opt.ContentLength = totalBytes
1805+ // }
1806+ // lilang : 2022-07-04
1807+ // 图片cgi不设置content-length的话,读不到body。图片处理cgi暂时不支持chunked,后面会修复。
1808+ if opt != nil && opt .ContentLength == 0 {
1809+ opt .ContentLength = totalBytes
1810+ }
1811+
1812+ }
1813+ reader := TeeReader (fd , nil , totalBytes , nil )
1814+ if s .client .Conf .EnableCRC {
1815+ reader .writer = crc64 .New (crc64 .MakeTable (crc64 .ECMA ))
1816+ }
1817+ if opt != nil && opt .Listener != nil {
1818+ reader .listener = opt .Listener
1819+ }
1820+
1821+ var res LivenessRecognitionResult
1822+ sendOpt := sendOptions {
1823+ baseURL : s .client .BaseURL .BucketURL ,
1824+ uri : "/" + encodeURIComponent (obj ) + "?ci-process=LivenessRecognition" ,
1825+ method : http .MethodPut ,
1826+ optQuery : query ,
1827+ body : reader ,
1828+ optHeader : opt ,
1829+ result : & res ,
1830+ }
1831+ resp , err := s .client .send (ctx , & sendOpt )
1832+
1833+ return & res , resp , err
1834+ }
0 commit comments