我嘗試使用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