Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
opencv python到kotlin的转换_Opencv_Kotlin_Opencv3.0_Detection - Fatal编程技术网

opencv python到kotlin的转换

opencv python到kotlin的转换,opencv,kotlin,opencv3.0,detection,Opencv,Kotlin,Opencv3.0,Detection,我正在尝试将python中可用的代码转换为我的android项目的kotlin。我使用的是yolo文件 def detect_person(image, confThreshold): img = np.copy(image) blob = cv2.dnn.blobFromImage(img, 1/255.0, (416, 416), swapRB=True, crop=False) net.setInput(blob) outputs = net.forward(names)

我正在尝试将python中可用的代码转换为我的android项目的kotlin。我使用的是yolo文件

def detect_person(image, confThreshold):
  img = np.copy(image)
  blob = cv2.dnn.blobFromImage(img, 1/255.0, (416, 416), swapRB=True, crop=False)
  net.setInput(blob)
  outputs = net.forward(names)
  outputs = np.vstack(outputs)
  H, W = image.shape[:2]
  boxes = []
  confidences = []
  classIDs = []

  for output in outputs:
        scores = output[5:]
        classID = np.argmax(scores)
        confidence = scores[classID]
        if confidence > confThreshold:
            x, y, w, h = output[:4] * np.array([W, H, W, H])
            p0 = int(x - w//2), int(y - h//2)
            p1 = int(x + w//2), int(y + h//2)
            boxes.append([*p0, int(w), int(h)])
            confidences.append(float(confidence))
            classIDs.append(classID)

  indices = cv2.dnn.NMSBoxes(boxes, confidences, confThreshold, confThreshold-0.1)
  
  bboxes = []
  confs = []
  if len(indices) > 0:
     for i in indices.flatten():
            (x, y) = (boxes[i][0], boxes[i][1])
            (w, h) = (boxes[i][2], boxes[i][3])
            # track only people in image 
            if classIDs[i] == 0:
               x0 = max(0,x)
               y0 = max(0,y)
               x1 = min(x0+w,img.shape[1])
               y1 = min(y0+h, img.shape[0])
            
               bboxes.append([x0,y0,x1,y1])
               confs.append(round(confidences[i],2))
              
  return bboxes,confs
到目前为止,我可以完成这项工作。我不知道这将如何以其他方式工作。这是我的个人检测代码

 fun detectPerson(img: Bitmap) {

        val imgMat = Mat()
        Utils.bitmapToMat(img, imgMat)

        val blob = Dnn.blobFromImage(
            imgMat,
            1.0,
            Size(300.0, 300.0),
            Scalar(104.0, 177.0, 123.0),
            false,
            false
        )

        maskModel?.setInput(blob)

//        todo what is the first parameter here....???
        val outputs = maskModel?.forward()
        val detections = arrayOf(outputs)


        val H = img.height
        val W = img.width

        var boxes = Mat()
        var confidences = Mat()
        var classIDs = Mat()


        for (output in detections) {


        }

    }
以上是正确的吗。在python中,当new.forward(名称)出现时,我会得到输出,这很好。但在科特林,我回到了垫子

关于NMSBoxes,我尝试查看python文档。它返回索引。但是,在kotlin的OpenCV中,我们需要在NMSBoxes中将索引作为参数传递?我该如何解决这个问题