Tag Archives: Pedestrian detection

[Solved] Tsingsee green rhinoceros video pedestrian intelligence detection test error panic: runtime error

In the previous article, we introduced the test of tsingsee green rhinoceros video pedestrian intelligent detection function in the scenic spot project. In the scenic spot project system, an error occurred when replacing the local file with the error message: “panic: runtime error: index out of range [1] with length 1”. This error means that the program runs beyond the index range, which will cause the program to crash.

First look at the code:

var allFile = ""
for _, dirfile := range dirfiles {
   fname := dirfile.Name()
   n := strings.Split(fname, "_")[1]
   allFile += fmt.Sprintf("%s/%s;", dir, n)
}
allFile = allFile[:len(allFile) -1]

nameSplit := strings.Split(arr[index].Filename, ";")
   log.Println("There are multiple files that need to be replaced:" + arr[index].Filename)

   DoLocalFile(0, nameSplit,  func() {
      index+=1
      DoValueToReplaceSource(arr, index, cb)
   })

   return

The above code is to splice the video files in all folders and use semicolons (“;”) as separators. However, an error will appear in the code: reference a slice with nil, that is, an element with subscript 0. This error will cause an index out of range error in the code, which will trigger panic and make the program unable to run normally.

The semicolon (“;”) segmentation is used here, so as long as a judgment is made, the character segmented from the semicolon needs to be greater than 1. If it is less than or equal to 1, an error will occur. The code is modified as follows:

nameSplit := strings.Split(arr[index].Filename, ";")
if len(nameSplit) > 1 {
   log.Println("There are multiple files that need to be replaced:" + arr[index].Filename)

   DoLocalFile(0, nameSplit,  func() {
      index+=1
      DoValueToReplaceSource(arr, index, cb)
   })

   return
} else {
   if IsExists(arr[index].Filename) {
      ChangeFile(arr[index].Filename)
   } else {
      log.Println("No path to this file")
   }
}

After modification, the error can be solved. Tsingsee Qingxi video will continue to expand the functions and advantages of the live video broadcasting system. On the one hand, it realizes intelligent judgment through AI intelligent analysis. On the other hand, it obtains the most vivid data information and carries out accurate calculation through Internet of things, big data and other technologies. You are welcome to understand or test.