E1696 无法打开 源 文件 "tbb/parallel_for.h" p2m - x64-Debug C:\Users\asus\source\repos\p2m\p2m\Model.cpp 6
时间: 2024-04-10 22:25:01 浏览: 178
根据您提供的错误信息,E1696是一个编译错误,表示无法打开源文件"tbb/parallel_for.h"。这个错误通常发生在编译器无法找到指定的头文件时。
"tbb/parallel_for.h"是Intel Threading Building Blocks(TBB)库的头文件之一,它提供了并行编程的功能。要解决这个错误,您需要确保TBB库已正确安装,并且编译器能够找到该库的头文件。
以下是一些可能的解决方法:
1. 确保您已正确安装了TBB库。您可以从Intel官方网站下载并安装最新版本的TBB库。
2. 检查您的编译器设置,确保它能够找到TBB库的头文件。您可能需要在编译器的包含目录中添加TBB库的路径。
3. 检查您的项目设置,确保正确地链接TBB库。您可能需要在链接器设置中添加TBB库的路径。
请注意,具体的解决方法可能因您使用的编译器和开发环境而有所不同。如果您仍然遇到困难,请提供更多关于您的项目和开发环境的信息,以便我能够提供更具体的帮助。
相关问题
[ INFO:0@0.108] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load D:\Program Files\opencv\opencv\build\x64\vc15\bin\opencv_core_parallel_onetbb460_64d.dll => FAILED
从错误信息来看,OpenCV在加载名为"opencv_core_parallel_onetbb460_64d.dll"的动态链接库时出现了问题。可能的原因之一是该动态链接库文件不存在或无法访问。
请确保以下几点:
1. 安装路径正确:确认OpenCV库的安装路径是否正确,特别是检查是否存在"opencv_core_parallel_onetbb460_64d.dll"文件。
2. 编译选项:如果你是自行编译OpenCV库,确保在编译过程中启用了并行处理支持以及相关的依赖库(如TBB)。
3. 环境变量:确保系统的环境变量中包含了OpenCV库的路径,以便运行时可以正确找到动态链接库。
如果问题仍然存在,建议尝试重新安装或编译OpenCV库,确保正确配置并启用了并行处理支持。如果问题仍然无法解决,请考虑在OpenCV社区或相关论坛上寻求帮助,提供更详细的错误信息和环境配置。
加速这一段代码例程#include <thread> #include <mutex> // 用于保护m_vpdEdgePoints和m_vdEdgeGradient的锁 std::mutex g_mutex; void process_edges(const cv::Mat& RoiMat, const std::vectorcv::Point2d& m_vpdEquinoxPoints, const double m_dMeasureLength, const double m_dMeasureHeight, const double m_dSigma, const int m_nThresholdCircle, const int m_nTranslationCircle, const std::vector<double>& m_vdMeasureAngle, std::vectorcv::Point2d& m_vpdEdgePoints, std::vector<double>& m_vdEdgeGradient, int start_idx, int end_idx, Extract1DEdgeCircle Extract1DEdgeCircle) { std::vector<Edge1D_Result> edges; for (int i = start_idx; i < end_idx; i++) { edges = Extract1DEdgeCircle.Get1DEdge(RoiMat, m_vpdEquinoxPoints[i], m_dMeasureLength, m_dMeasureHeight,m_vdMeasureAngle[i], m_dSigma, m_nThresholdCircle, m_nTranslationCircle == 1 ? Translation::Poisitive : Translation::Negative, Selection::Strongest); // 使用锁保护m_vpdEdgePoints和m_vdEdgeGradient //std::lock_guardstd::mutex lock(g_mutex); for (int j = 0; j < edges.size(); j++) { m_vpdEdgePoints.push_back(edges[j].m_pdEdgePoint); m_vdEdgeGradient.push_back(edges[j].m_dGradient); } } } int main() { int m = m_vpdEquinoxPoints.size(); const int num_threads = 10; std::vectorstd::thread threads(num_threads); std::vectorstd::vectorcv::Point2d edge_points(num_threads); std::vector<std::vector<double>> edge_gradients(num_threads); for (int i = 0; i < num_threads; i++) { int start_idx = i * m / num_threads; int end_idx = (i + 1) * m / num_threads; threads[i] = std::thread(process_edges, std::ref(RoiMat), std::ref(m_vpdEquinoxPoints), m_dMeasureLength, m_dMeasureHeight, m_dSigma, m_nThresholdCircle, m_nTranslationCircle, std::ref(m_vdMeasureAngle), std::ref(edge_points[i]), std::ref(edge_gradients[i]), start_idx, end_idx, Extract1DEdgeCircle); } for (int i = 0; i < num_threads; i++) { threads[i].join(); // 合并结果 m_vpdEdgePoints.insert(m_vpdEdgePoints.end(), edge_points[i].begin(), edge_points[i].end()); m_vdEdgeGradient.insert(m_vdEdgeGradient.end(), edge_gradients[i].begin(), edge_gradients[i].end()); } return 0; }
可以尝试使用 OpenMP 或者 TBB 等并行编程库来进行加速。具体实现方式如下:
1. 使用 OpenMP
在循环中添加 `#pragma omp parallel for` 来开启并行化,代码如下:
```cpp
void process_edges(const cv::Mat& RoiMat, const std::vector<cv::Point2d>& m_vpdEquinoxPoints, const double m_dMeasureLength, const double m_dMeasureHeight, const double m_dSigma, const int m_nThresholdCircle, const int m_nTranslationCircle, const std::vector<double>& m_vdMeasureAngle, std::vector<cv::Point2d>& m_vpdEdgePoints, std::vector<double>& m_vdEdgeGradient, int start_idx, int end_idx, Extract1DEdgeCircle Extract1DEdgeCircle) {
std::vector<Edge1D_Result> edges;
#pragma omp parallel for
for (int i = start_idx; i < end_idx; i++) {
edges = Extract1DEdgeCircle.Get1DEdge(RoiMat, m_vpdEquinoxPoints[i], m_dMeasureLength, m_dMeasureHeight,m_vdMeasureAngle[i], m_dSigma, m_nThresholdCircle, m_nTranslationCircle == 1 ? Translation::Poisitive : Translation::Negative, Selection::Strongest);
// 使用锁保护m_vpdEdgePoints和m_vdEdgeGradient
std::lock_guard<std::mutex> lock(g_mutex);
for (int j = 0; j < edges.size(); j++) {
m_vpdEdgePoints.push_back(edges[j].m_pdEdgePoint);
m_vdEdgeGradient.push_back(edges[j].m_dGradient);
}
}
}
int main() {
int m = m_vpdEquinoxPoints.size();
const int num_threads = 10;
std::vector<std::vector<cv::Point2d>> edge_points(num_threads);
std::vector<std::vector<double>> edge_gradients(num_threads);
#pragma omp parallel num_threads(num_threads)
{
int tid = omp_get_thread_num();
int start_idx = tid * m / num_threads;
int end_idx = (tid + 1) * m / num_threads;
process_edges(RoiMat, m_vpdEquinoxPoints, m_dMeasureLength, m_dMeasureHeight, m_dSigma, m_nThresholdCircle, m_nTranslationCircle, m_vdMeasureAngle, edge_points[tid], edge_gradients[tid], start_idx, end_idx, Extract1DEdgeCircle);
}
// 合并结果
for (int i = 0; i < num_threads; i++) {
m_vpdEdgePoints.insert(m_vpdEdgePoints.end(), edge_points[i].begin(), edge_points[i].end());
m_vdEdgeGradient.insert(m_vdEdgeGradient.end(), edge_gradients[i].begin(), edge_gradients[i].end());
}
return 0;
}
```
2. 使用 TBB
在循环中使用 `tbb::parallel_for` 来开启并行化,代码如下:
```cpp
#include <tbb/parallel_for.h>
void process_edges(const cv::Mat& RoiMat, const std::vector<cv::Point2d>& m_vpdEquinoxPoints, const double m_dMeasureLength, const double m_dMeasureHeight, const double m_dSigma, const int m_nThresholdCircle, const int m_nTranslationCircle, const std::vector<double>& m_vdMeasureAngle, std::vector<cv::Point2d>& m_vpdEdgePoints, std::vector<double>& m_vdEdgeGradient, int start_idx, int end_idx, Extract1DEdgeCircle Extract1DEdgeCircle) {
std::vector<Edge1D_Result> edges;
tbb::parallel_for(start_idx, end_idx, [&](int i) {
edges = Extract1DEdgeCircle.Get1DEdge(RoiMat, m_vpdEquinoxPoints[i], m_dMeasureLength, m_dMeasureHeight,m_vdMeasureAngle[i], m_dSigma, m_nThresholdCircle, m_nTranslationCircle == 1 ? Translation::Poisitive : Translation::Negative, Selection::Strongest);
// 使用锁保护m_vpdEdgePoints和m_vdEdgeGradient
std::lock_guard<std::mutex> lock(g_mutex);
for (int j = 0; j < edges.size(); j++) {
m_vpdEdgePoints.push_back(edges[j].m_pdEdgePoint);
m_vdEdgeGradient.push_back(edges[j].m_dGradient);
}
});
}
int main() {
int m = m_vpdEquinoxPoints.size();
const int num_threads = 10;
std::vector<std::vector<cv::Point2d>> edge_points(num_threads);
std::vector<std::vector<double>> edge_gradients(num_threads);
tbb::parallel_for(0, num_threads, [&](int tid) {
int start_idx = tid * m / num_threads;
int end_idx = (tid + 1) * m / num_threads;
process_edges(RoiMat, m_vpdEquinoxPoints, m_dMeasureLength, m_dMeasureHeight, m_dSigma, m_nThresholdCircle, m_nTranslationCircle, m_vdMeasureAngle, edge_points[tid], edge_gradients[tid], start_idx, end_idx, Extract1DEdgeCircle);
});
// 合并结果
for (int i = 0; i < num_threads; i++) {
m_vpdEdgePoints.insert(m_vpdEdgePoints.end(), edge_points[i].begin(), edge_points[i].end());
m_vdEdgeGradient.insert(m_vdEdgeGradient.end(), edge_gradients[i].begin(), edge_gradients[i].end());
}
return 0;
}
```
需要注意的是,在使用锁时,应该使用 `std::lock_guard<std::mutex>` 或者 `std::unique_lock<std::mutex>` 来保护临界区域。
阅读全文