使用OpenCV在Java中加载并行处理模块时出错

ovfsdjhp  于 2023-01-13  发布在  Java
关注(0)|答案(1)|浏览(678)

我尝试使用Java中的OpenCV库检测图像中的人脸。我使用的是OpenCV版本4.7.0-dev。当我运行程序时,我收到以下错误:

[ INFO:0@0.885] global registry_parallel.impl.hpp:96 cv::parallel::ParallelBackendRegistry::ParallelBackendRegistry core(parallel): Enabled backends(3, sorted by priority): ONETBB(1000); TBB(990); OPENMP(980)
[ INFO:0@0.885] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\Users\ricar\OneDrive\Documentos\libraries\opencv\build\java\x64\opencv_core_parallel_onetbb470_64d.dll => FAILED
[ INFO:0@0.886] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_onetbb470_64d.dll => FAILED
[ INFO:0@0.886] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\Users\ricar\OneDrive\Documentos\libraries\opencv\build\java\x64\opencv_core_parallel_tbb470_64d.dll => FAILED
[ INFO:0@0.886] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_tbb470_64d.dll => FAILED
[ INFO:0@0.887] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\Users\ricar\OneDrive\Documentos\libraries\opencv\build\java\x64\opencv_core_parallel_openmp470_64d.dll => FAILED
[ INFO:0@0.887] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_openmp470_64d.dll => FAILED
[ INFO:0@1.067] global ocl.cpp:1186 cv::ocl::haveOpenCL Initialize OpenCL runtime...
[ INFO:0@1.977] global ocl.cpp:1192 cv::ocl::haveOpenCL OpenCL: found 2 platforms
[ INFO:0@1.977] global ocl.cpp:984 cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: initializing thread execution context
[ INFO:0@1.977] global ocl.cpp:994 cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: creating new execution context...
[ INFO:0@2.571] global ocl.cpp:1012 cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: device=NVIDIA GeForce MX230
[ INFO:0@2.571] global ocl.cpp:5370 cv::ocl::Context::Impl::__init_buffer_pools OpenCL: Initializing buffer pool for context@0 with max capacity: poolSize=0 poolSizeHostPtr=0

这是我的代码。我相信我的问题是安装或配置问题。

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
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;

class Main{

    public static void main(String[] args){
        
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        
        Mat image = Imgcodecs.imread("C:\\Users\\ricar\\Downloads\\DSC02281.JPG");
        
        CascadeClassifier classifier = new CascadeClassifier("C:\\Users\\ricar\\OneDrive\\Documentos\\workspace\\LearningJava\\src\\haarcascade_frontalface_default.xml");
        MatOfRect faceDetections = new MatOfRect();
        classifier.detectMultiScale(image, faceDetections);
        
        for(Rect rect : faceDetections.toArray()) {
            
            Imgproc.rectangle(image, rect, new Scalar(0, 0, 255));
            
        }
        Imgcodecs.imwrite("C:\\Users\\ricar\\Downloads\\output.jpg", image);
        
    }
    
}
vql8enpb

vql8enpb1#

错误消息表明问题出在OpenCV并行插件上。这可能是由于OpenCV用于并行处理的TBB库的版本丢失或不兼容。
您应该检查是否安装了正确版本的TBB,以及它是否位于系统PATH环境变量中包含的目录中。

相关问题