isapi_smart_lineDetection.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package isapi
  2. import (
  3. "encoding/json"
  4. "encoding/xml"
  5. )
  6. //能力
  7. //http://192.168.1.64/ISAPI/Smart/LineDetection/1/capabilities
  8. //http://192.168.1.64/ISAPI/Smart/channels/1/calibrations/capabilities
  9. // LineDetectionParam 越界侦测
  10. type LineDetectionParam struct {
  11. ID string `xml:"id" json:"id"`
  12. Enabled string `xml:"enabled" json:"enabled"`
  13. NormalizedScreenSize struct {
  14. NormalizedScreenWidth string `xml:"normalizedScreenWidth" json:"normalizedScreenWidth"`
  15. NormalizedScreenHeight string `xml:"normalizedScreenHeight" json:"normalizedScreenHeight"`
  16. } `xml:"normalizedScreenSize" json:"normalizedScreenSize"`
  17. LineItemList struct {
  18. Size string `xml:"size,attr" json:"size"`
  19. LineItem []struct {
  20. ID string `xml:"id" json:"id"`
  21. Enabled string `xml:"enabled" json:"enabled"`
  22. SensitivityLevel string `xml:"sensitivityLevel" json:"sensitivityLevel"`
  23. DirectionSensitivity string `xml:"directionSensitivity"json:"directionSensitivity"`
  24. DetectionTarget string `xml:"detectionTarget" json:"detectionTarget"`
  25. AlarmConfidence string `xml:"alarmConfidence" json:"alarmConfidence"`
  26. CoordinatesList struct {
  27. Coordinates []struct {
  28. PositionX string `xml:"positionX" json:"positionX"`
  29. PositionY string `xml:"positionY" json:"positionY"`
  30. } `xml:"Coordinates" json:"Coordinates"`
  31. } `xml:"CoordinatesList" json:"CoordinatesList"`
  32. } `xml:"LineItem" json:"LineItem"`
  33. } `xml:"LineItemList" json:"LineItemList"`
  34. IsSupportMultiScene string `xml:"isSupportMultiScene" json:"isSupportMultiScene"`
  35. RecogRuleType string `xml:"recogRuleType" json:"recogRuleType"`
  36. }
  37. func (c *Client) GetLineDetectionCap() (resp LineDetectionCap, err error) {
  38. bytes, err := c.CommonGet("/ISAPI/Smart/LineDetection/1/capabilities")
  39. if err != nil {
  40. return
  41. }
  42. err = xml.Unmarshal(bytes, &resp)
  43. detection, _ := c.GetLineDetection()
  44. for i, v := range detection.LineItemList.LineItem {
  45. resp.LineItemList.LineItem[i].AlarmConfidence.Text = v.AlarmConfidence
  46. }
  47. return
  48. }
  49. func (c *Client) GetSizeLd() (resp SmartCalibrationList, err error) {
  50. bytes, err := c.CommonGet("/ISAPI/Smart/channels/1/calibrations/linedetection")
  51. if err != nil {
  52. return
  53. }
  54. err = xml.Unmarshal(bytes, &resp)
  55. return
  56. }
  57. func (c *Client) PutSizeLd(data []byte) (resp ResponseStatus, err error) {
  58. var info SmartCalibrationList
  59. err = json.Unmarshal(data, &info)
  60. if err != nil {
  61. return ResponseStatus{}, err
  62. }
  63. marshal, err := xml.Marshal(info)
  64. if err != nil {
  65. return ResponseStatus{}, err
  66. }
  67. respData, err := c.CommonPut(marshal, "/ISAPI/Smart/channels/1/calibrations/linedetection")
  68. if err != nil {
  69. return ResponseStatus{}, err
  70. }
  71. err = xml.Unmarshal(respData, &resp)
  72. if err != nil {
  73. return ResponseStatus{}, err
  74. }
  75. return
  76. }
  77. // GetLineDetection 获取单个通道越界侦测规则
  78. func (c *Client) GetLineDetection() (resp LineDetectionParam, err error) {
  79. bytes, err := c.CommonGet("/ISAPI/Smart/LineDetection/1")
  80. if err != nil {
  81. return
  82. }
  83. err = xml.Unmarshal(bytes, &resp)
  84. return
  85. }
  86. // PutLineDetection 配置单个通道越界侦测规则
  87. func (c *Client) PutLineDetection(data []byte) (resp ResponseStatus, err error) {
  88. var info LineDetectionParam
  89. err = json.Unmarshal(data, &info)
  90. if err != nil {
  91. return ResponseStatus{}, err
  92. }
  93. marshal, err := xml.Marshal(info)
  94. if err != nil {
  95. return ResponseStatus{}, err
  96. }
  97. respData, err := c.CommonPut(marshal, "/ISAPI/Smart/LineDetection/1")
  98. if err != nil {
  99. return ResponseStatus{}, err
  100. }
  101. err = xml.Unmarshal(respData, &resp)
  102. if err != nil {
  103. return ResponseStatus{}, err
  104. }
  105. return
  106. }
  107. type LineDetectionCap struct {
  108. ID string `xml:"id" json:"id"`
  109. Enabled struct {
  110. Text string `xml:",chardata" json:"value"`
  111. Opt string `xml:"opt,attr" json:"opt"`
  112. } `xml:"enabled" json:"enabled"`
  113. NormalizedScreenSize struct {
  114. NormalizedScreenWidth string `xml:"normalizedScreenWidth" json:"normalizedScreenWidth"`
  115. NormalizedScreenHeight string `xml:"normalizedScreenHeight" json:"normalizedScreenHeight"`
  116. } `xml:"normalizedScreenSize" json:"normalizedScreenSize"`
  117. LineItemList struct {
  118. Size string `xml:"size,attr" json:"size"`
  119. LineItem []struct {
  120. ID string `xml:"id" json:"id"`
  121. Enabled struct {
  122. Text string `xml:",chardata" json:"value"`
  123. Opt string `xml:"opt,attr" json:"opt"`
  124. } `xml:"enabled" json:"enabled"`
  125. SensitivityLevel struct {
  126. Text string `xml:",chardata" json:"value"`
  127. Min string `xml:"min,attr" json:"min"`
  128. Max string `xml:"max,attr" json:"max"`
  129. } `xml:"sensitivityLevel" json:"sensitivityLevel"`
  130. DirectionSensitivity struct {
  131. Text string `xml:",chardata" json:"value"`
  132. Opt string `xml:"opt,attr" json:"opt"`
  133. } `xml:"directionSensitivity" json:"directionSensitivity"`
  134. CoordinatesList struct {
  135. Coordinates []struct {
  136. PositionX string `xml:"positionX" json:"positionX"`
  137. PositionY string `xml:"positionY" json:"positionY"`
  138. } `xml:"Coordinates" json:"Coordinates"`
  139. } `xml:"CoordinatesList" json:"CoordinatesList"`
  140. DetectionTarget struct {
  141. Text string `xml:",chardata" json:"value"`
  142. Opt string `xml:"opt,attr" json:"opt"`
  143. } `xml:"detectionTarget" json:"detectionTarget"`
  144. AlarmConfidence struct {
  145. Text string `xml:",chardata" json:"value"`
  146. Opt string `xml:"opt,attr" json:"opt"`
  147. Def string `xml:"def,attr" json:"def"`
  148. } `xml:"alarmConfidence" json:"alarmConfidence"`
  149. } `xml:"LineItem" json:"LineItem"`
  150. } `xml:"LineItemList" json:"LineItemList"`
  151. IsSupportMultiScene string `xml:"isSupportMultiScene" json:"isSupportMultiScene"`
  152. RecogRuleType string `xml:"recogRuleType" json:"recogRuleType"`
  153. IsSupportHumanMisinfoFilter string `xml:"isSupportHumanMisinfoFilter" json:"isSupportHumanMisinfoFilter"`
  154. IsSupportVehicleMisinfoFilter string `xml:"isSupportVehicleMisinfoFilter" json:"isSupportVehicleMisinfoFilter"`
  155. IsSupportTargetMultiSelect string `xml:"isSupportTargetMultiSelect" json:"isSupportTargetMultiSelect"`
  156. IsSupportAllDayUpload string `xml:"isSupportAllDayUpload" json:"isSupportAllDayUpload"`
  157. }