Java 打开CV 3.0.0人脸检测MultiScale失败
为什么我试图让开放简历的人脸检测样本工作。 第一个问题在这里得到了解决: 我的代码现在如下所示:Java 打开CV 3.0.0人脸检测MultiScale失败,java,opencv,Java,Opencv,为什么我试图让开放简历的人脸检测样本工作。 第一个问题在这里得到了解决: 我的代码现在如下所示: package org.maxbit.opencv.samples; import java.awt.image.ImageProducer; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfRect; import org.opencv.core.Point; import
package org.maxbit.opencv.samples;
import java.awt.image.ImageProducer;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");
// Create a face detector from the cascade file in the resources
// directory.
CascadeClassifier faceDetector = new CascadeClassifier();
// System.out.println(getClass().getResource("libpcascade_frontalface.xml").getPath());
if(!faceDetector.load("D:/lbpcascade_frontalface.xml"))
System.out.println("ldpcascade_frontalface.xml not found!");
System.out.println("Loading analyse method Done!");
Mat image = Imgcodecs.imread("D:/lena.png");
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
// Draw a bounding box around each face.
for (Rect rect : faceDetections.toArray()) {
Imgproc.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(255, 0, 0));
}
// Save the visualized detection.
String filename = "faceDetection.png";
System.out.println(String.format("Writing %s", filename));
Imgcodecs.imwrite(filename, image);
}
}
public class SampleB {
public static void main(String[] args) {
System.out.println("Hello, OpenCV "+Core.NATIVE_LIBRARY_NAME);
// Load the native library.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
new DetectFaceDemo().run();
}
}
当我开始此操作时,会出现以下错误:
OpenCV Error: Assertion failed (clEnqueueReadBuffer(q, (cl_mem)u->handle, CL_TRUE, 0, u->size, alignedPtr.getAlignedPtr(), 0, 0, 0) == CL_SUCCESS) in cv::ocl::OpenCLAllocator::map, file ..\..\..\..\opencv\modules\core\src\ocl.cpp, line 3961
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\ocl.cpp:3961: error: (-215) clEnqueueReadBuffer(q, (cl_mem)u->handle, CL_TRUE, 0, u->size, alignedPtr.getAlignedPtr(), 0, 0, 0) == CL_SUCCESS in function cv::ocl::OpenCLAllocator::map
]
at org.opencv.objdetect.CascadeClassifier.detectMultiScale_1(Native Method)
at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:176)
at org.maxbit.opencv.samples.DetectFaceDemo.run(SampleB.java:35)
at org.maxbit.opencv.samples.SampleB.main(SampleB.java:57)
它指向这个我知道这是一篇老文章,但我可以通过不同的文件路径设置来解决这个问题。我使用了下面的方法来修复文件路径,我只是在下一行添加了它,它可以工作,当然代码应该清理得更好一些
faceDetector.load("C:\\workspace\\OpenCV_Starting\\bin\\main\\resources\\lbpcascade_frontalface.xml");
(当然C:\Workspace\stuff是我的电脑,所以请适当更改!)我知道这是一篇旧文章,但我可以通过不同的文件路径设置来解决这个问题。我使用了下面的方法来修复文件路径,我只是在下一行添加了它,它可以工作,当然代码应该清理得更好一些
faceDetector.load("C:\\workspace\\OpenCV_Starting\\bin\\main\\resources\\lbpcascade_frontalface.xml");
(当然C:\Workspace\stuff是我的电脑,所以请适当更改!)我知道这是一篇旧文章,但我可以通过不同的文件路径设置来解决这个问题。我使用了下面的方法来修复文件路径,我只是在下一行添加了它,它可以工作,当然代码应该清理得更好一些
faceDetector.load("C:\\workspace\\OpenCV_Starting\\bin\\main\\resources\\lbpcascade_frontalface.xml");
(当然C:\Workspace\stuff是我的电脑,所以请适当更改!)我知道这是一篇旧文章,但我可以通过不同的文件路径设置来解决这个问题。我使用了下面的方法来修复文件路径,我只是在下一行添加了它,它可以工作,当然代码应该清理得更好一些
faceDetector.load("C:\\workspace\\OpenCV_Starting\\bin\\main\\resources\\lbpcascade_frontalface.xml");
(当然C:\Workspace\stuff是我的计算机,所以请适当更改!)您的问题是什么?为了确保这不是opencl/build问题,在调用
run()
之前,您是否可以使用java包装器作为,cv::ocl::setUseOpenCL(false)
的链接。阅读lena.jpgkind后还要检查image.empty(),如果您碰巧找到了错误的根本原因,请更新答案。我没有在windows上运行此操作,我切换到linux并使用cpp而不是java,它运行得很好。您有什么问题吗?在调用run()之前,确保这不是opencl/build问题
您是否可以使用java包装器作为,cv::ocl::setUseOpenCL(false)
在这个链接上。阅读lena.jpgkind后还要检查image.empty(),如果您碰巧找到了错误的根本原因,请更新答案。我没有在windows上运行此操作,我切换到linux并使用cpp而不是java,它运行得很好。您有什么问题吗?在调用run()之前,确保这不是opencl/build问题
您是否可以使用java包装器作为,cv::ocl::setUseOpenCL(false)
在这个链接上。阅读lena.jpgkind后还要检查image.empty(),如果您碰巧找到了错误的根本原因,请更新答案。我没有在windows上运行此操作,我切换到linux并使用cpp而不是java,它运行得很好。您有什么问题吗?在调用run()之前,确保这不是opencl/build问题
您是否可以使用java包装器作为,cv::ocl::setUseOpenCL(false)
在这个链接上。阅读lena.jpgkind后,还要检查image.empty(),如果您碰巧找到了错误的根本原因,请更新答案。我没有在windows上运行此操作,我切换到linux,使用cpp而不是java,它运行得非常好。