c++ 中的错误android studio中头文件路径的代码

发布于 2025-01-16 20:26:35 字数 4319 浏览 0 评论 0原文

我正在尝试使用 android studio 开发一个 android 应用程序,通过合并用于面部标志检测的 C++ 代码。我正在使用 android studio 中提供的本机 C++ 活动。我面临的问题是在文件夹 app->src->main->cpp 中,所有 c++ 相关文件(包括 CMakeLists.txt、native-lib.cpp)都保存在同一个文件夹中文件夹以便更好地访问。但是我收到头文件的路径错误,并且不可能手动编辑所有头文件中的路径。任何人都可以就如何包含头文件而不出现路径错误提出任何建议吗?

我无法在 android studio 中将 opencv dlib 与本机 c++ 连接。有一个包含文件夹,但它不包含 opencv dlib 标头。即使他们也不允许导入 android opencv sdk 模块。我试图手动将头文件包含在上述路径中,但它给出了路径错误。

#include <jni.h>
#include "opencv.h"
#include "highgui.hpp"
#include "frontal_face_detector.h"
#include "render_face_detections.h"
#include "image_processing.h"
#include "gui_widgets.h"

using namespace dlib;
using namespace std;
using namespace cv;

extern "C" JNIEXPORT jstring JNICALL
Java_com_example_facedetectionc3_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {

        Mat img = imread("Sample1.jpg");
// Load face detection and pose estimation models.
        frontal_face_detector detector = get_frontal_face_detector();
        cvtColor(img, img, COLOR_BGR2GRAY);
        cv_image<bgr_pixel> dlib_img(img);
// Detect faces
        vector<rectangle> faces = detector(dlib_img);
        int totalFaces = facesRects.size();
//face detection rectangle
        vector<full_object_detection> shapes;
        for (int i = 0; i < faces.size(); i++){
                rectangle r((long)(faces[i].left()),
                            (long)(faces[i].top()),
                            (long)(faces[i].right()),
                            (long)(faces[i].bottom()));
        }
        Rect roi(faces[i].left(),faces[i].top(),faces[i].right(),faces[i].bottom());
        face = dlib_img(roi);
        cvtColor(dlib_img, dlib_img, COLOR_BGR2RGB);
//define landmark detector
        shape_predictor landmarkDetector;
        deserialize("shape_predictor_68_face_landmarks.dat")>>landmarkDetector;
//to get the points
        for(int i=0; i<totalFaces; i++){
                full_object_detection faceLandmark = landmarkDetector(dlib_img, faceRects[i]);
        }
        imshow("Image", img);
        waitKey(0);
        return 0;
}

这是我的 native-lib.cpp 代码。我的头文件有错误,但是如何编辑头文件。而且我在这些头文件的路径中遇到了一些问题。 这是我的 CMakeLists.txt 文件。

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.10.2)

#opencv
set(OpenCV_STATIC_on)
set(OpenCV_DIR ${OPENCV_ANDROID}/sdk/native/jni)
find_package(OpenCV.REQUIRED)

# Declares and names the project.

project("facedetectionc3")

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             opencv_facedetection.cpp
             native-lib.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )
find_library(inigraphics-lib jnigraphics)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${openCV_LIBS}
                       ${jnigraphics-libs}
                       ${log-lib} )

有什么建议吗?

I am trying to develop an android application using android studio by incorporating c++ code for facial landmark detection. I am using the native c++ activity provided in the android studio. The problem I am facing is in the folder app->src->main->cpp all the c++ related files including CMakeLists.txt, native-lib.cpp are saved I have saved all the related header files in the same folder for better access. But I am getting path errors for the header files and it is quite impossible to manually edit path in all the header files. Can anyone please give any suggestions on how to include the header files without path error?

I am unable to connect opencv dlib with native c++ in android studio. There is an include folder but it does not contain opencv dlib headers. Even they are not allowing to import android opencv sdk module. I was trying to manually include the header files in the above mentioned path, but it is giving path error.

#include <jni.h>
#include "opencv.h"
#include "highgui.hpp"
#include "frontal_face_detector.h"
#include "render_face_detections.h"
#include "image_processing.h"
#include "gui_widgets.h"

using namespace dlib;
using namespace std;
using namespace cv;

extern "C" JNIEXPORT jstring JNICALL
Java_com_example_facedetectionc3_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {

        Mat img = imread("Sample1.jpg");
// Load face detection and pose estimation models.
        frontal_face_detector detector = get_frontal_face_detector();
        cvtColor(img, img, COLOR_BGR2GRAY);
        cv_image<bgr_pixel> dlib_img(img);
// Detect faces
        vector<rectangle> faces = detector(dlib_img);
        int totalFaces = facesRects.size();
//face detection rectangle
        vector<full_object_detection> shapes;
        for (int i = 0; i < faces.size(); i++){
                rectangle r((long)(faces[i].left()),
                            (long)(faces[i].top()),
                            (long)(faces[i].right()),
                            (long)(faces[i].bottom()));
        }
        Rect roi(faces[i].left(),faces[i].top(),faces[i].right(),faces[i].bottom());
        face = dlib_img(roi);
        cvtColor(dlib_img, dlib_img, COLOR_BGR2RGB);
//define landmark detector
        shape_predictor landmarkDetector;
        deserialize("shape_predictor_68_face_landmarks.dat")>>landmarkDetector;
//to get the points
        for(int i=0; i<totalFaces; i++){
                full_object_detection faceLandmark = landmarkDetector(dlib_img, faceRects[i]);
        }
        imshow("Image", img);
        waitKey(0);
        return 0;
}

This is my native-lib.cpp code. I am having error in the header files, but how can I edit the header files. And also I am having some problem in path of these header files.
This is my CMakeLists.txt file.

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.10.2)

#opencv
set(OpenCV_STATIC_on)
set(OpenCV_DIR ${OPENCV_ANDROID}/sdk/native/jni)
find_package(OpenCV.REQUIRED)

# Declares and names the project.

project("facedetectionc3")

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             opencv_facedetection.cpp
             native-lib.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )
find_library(inigraphics-lib jnigraphics)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${openCV_LIBS}
                       ${jnigraphics-libs}
                       ${log-lib} )

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文