我正在尝试开发一个应用程序来检测某些对象,例如人、车辆和树木。作为开始,我尝试移植OpenCV 行人样本,但我得到了一个非常低的帧速率和很多误报。
由于我刚刚开始使用 OpenCV 并且对 C++ 也不太了解,因此我可能做出了不正确的解释和昂贵的计算。
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Mat frame = inputFrame.rgba();
float minScale = 0.4f, maxScale = 5; /* minimum and maximum scale to detect */
int totalScales = 55; /* preferred number of scales between min and max */
int threshold = -1; /* detections with score less then threshold will be ignored */
HOGDescriptor hog = new HOGDescriptor();
hog.setSVMDetector(HOGDescriptor.getDefaultPeopleDetector());
MatOfRect foundLocations = new MatOfRect();
MatOfDouble foundWeights = new MatOfDouble();
Mat tempMat = new Mat(frame.rows(), frame.cols(), CvType.CV_8UC3);
Imgproc.cvtColor(frame, tempMat, Imgproc.COLOR_RGBA2RGB);
hog.detectMultiScale(tempMat, foundLocations, foundWeights, 1.5, new Size(8,8),
new Size(32, 32), 1.05, 2, false);
Vector<Rect> foundLocationsFilteredList = new Vector<Rect>();
filterRects(foundLocations.toList(), foundLocationsFilteredList);
for (Rect foundLocation : foundLocationsFilteredList) {
Core.rectangle(frame, foundLocation.tl(), foundLocation.br(), new Scalar(0, 255, 0), 3);
}
tempMat.release();
return frame;
}
private final void filterRects(List<Rect> candidates, List<Rect> objects) {
for (int i = 0; i < candidates.size(); ++i) {
Rect r = candidates.get(i);
int j;
for (j = 0; j < candidates.size(); ++j) {
if (j != i && r.equals(candidates.get(j)))
break;
}
if (j == candidates.size())
objects.add(r);
}
}
- 如果使用 JNI 完成帧处理会更快吗?还是采用不同的方法会更好?
- 我应该如何进行多物体检测