我尝试使用opencv加载图像,并使用tensorflow框架对其进行进一步处理。不幸的是我得到了一个非常奇怪的行为:tf_cc_binary()使opencv无法加载图像
该图像在Bazel中使用cc_binary(...)
没有问题加载。将其更改为tf_cc_binary(...)
不会停止编译或运行代码,但opencv无法再加载任何图像。
load("//tensorflow:tensorflow.bzl", "tf_cc_binary")
#tf_cc_binary(<-- using this, no image could be loaded anymore
cc_binary(
name = "main",
srcs = ["main.cpp"],
linkopts = [
"-lopencv_core",
"-lopencv_highgui",
"-lopencv_imgcodecs",
"-lopencv_imgproc",
],
visibility=["//visibility:public"]
)
我使用opencv网站的标准示例代码。再次,它是否工作正常,图像是使用cc_binary(
加载的:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat image;
image = imread("tensorflow/test/imageHolder/data/example.jpg", CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
我发现tf_cc_binary(...)
这个定义:
# Links in the framework shared object
# (//third_party/tensorflow:libtensorflow_framework.so) when not building
# statically. Also adds linker options (rpaths) so that the framework shared
# object can be found.
def tf_cc_binary(name,
srcs=[],
deps=[],
linkopts=[],
**kwargs):
native.cc_binary(
name=name,
srcs=srcs + _binary_additional_srcs(),
deps=deps + if_mkl(
[
"//third_party/mkl:intel_binary_blob",
],
),
linkopts=linkopts + _rpath_linkopts(name),
**kwargs)
我甚至不明白到底是什么问题。我该如何解决它?
你对数据的依赖是什么意思? – Jonas
[this]中指定的依赖关系(https://docs.bazel.build/versions/master/be/common-definitions.html#common.data)属性。 – mhlopko