October 22, 2024
Chicago 12, Melborne City, USA
java

Erro no OpenCV CascadeClassifier com Java e Spring


Estou desenvolvendo um algoritmo de reconhecimento facial, usando Java com Spring Boot e OpenCV.

@Service
public class ReconhecimentoFacialService {
    static{
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // load opencv_java
    }

    @Autowired
    private AlunoRepository alunoRepository;

    private CascadeClassifier faceDetector;

    @PostConstruct
    public void init() throws URISyntaxException {
        System.out.println("\nPOST CONSTRUCT ReconhecimentoFacialService");

        String xmlFilePath = "C:/Users/MeuUsuario/Documents/GitHub/projeto/backend/src/main/resources/haarcascade_frontalface_alt.xml";
        System.out.println("XML File Path: " + xmlFilePath);
        this.faceDetector = new CascadeClassifier(xmlFilePath);
    }

Já adicionei a dependência no no pom.xml, como demonstrado abaixo

        <!-- OPENCV -->
        <!-- https://mvnrepository.com/artifact/org.openpnp/opencv -->
        <dependency>
            <groupId>org.openpnp</groupId>
            <artifactId>opencv</artifactId>
            <version>4.9.0-0</version>
        </dependency>

Mas ao inicializar a aplicação, recebo um erro no CascadeFilter, como se ele não pudesse inicializar o objeto, ou não achasse o arquivo xml, não sei afirmar.
A exceção é:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reconhecimentoFacialService': Invocation of init method failed z
Caused by: java.lang.UnsatisfiedLinkError: 'long org.opencv.objdetect.CascadeClassifier.CascadeClassifier_1(java.lang.String)'

Alguém consegue me ajudar a resolver? Já tentei colocar o dll do opencv no java/bin, configurar no inteliji, mas nada resolveu.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video