<p dir="auto">I try to load an image with opencv and work further on it with the tensorflow framework. Unfortunately I get a really weird behaviour:</p>
<p dir="auto">The image is loaded without problems using <code class="notranslate">cc_binary(...)</code> in Bazel. Changing it to <code class="notranslate">tf_cc_binary(...)</code> doesn't stop the code from compilation or running, but opencv can't load any images any more.</p>
<h3 dir="auto">Source code / logs</h3>
<p dir="auto">This is my BUILD file:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="load(&quot;//tensorflow:tensorflow.bzl&quot;, &quot;tf_cc_binary&quot;)

#tf_cc_binary( &lt;-- using this, no image could be loaded anymore
cc_binary(
    name = &quot;main&quot;,
    srcs = [&quot;main.cpp&quot;],
    linkopts = [
        &quot;-lopencv_core&quot;,
        &quot;-lopencv_highgui&quot;,
        &quot;-lopencv_imgcodecs&quot;,
        &quot;-lopencv_imgproc&quot;,
    ],
    visibility=[&quot;//visibility:public&quot;]
)"><pre class="notranslate"><code class="notranslate">load("//tensorflow:tensorflow.bzl", "tf_cc_binary")

#tf_cc_binary( &lt;-- 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"]
)
</code></pre></div>
<p dir="auto">I use the standard example code from the opencv website. Again, it is working and the image gets loaded using <code class="notranslate">cc_binary(</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#include &lt;opencv2/core/core.hpp&gt;
#include &lt;opencv2/highgui/highgui.hpp&gt;
#include &lt;iostream&gt;

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    Mat image;
    image = imread(&quot;tensorflow/test/imageHolder/data/example.jpg&quot;, CV_LOAD_IMAGE_COLOR);   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout &lt;&lt;  &quot;Could not open or find the image&quot; &lt;&lt; std::endl ;
        return -1;
    }

    namedWindow( &quot;Display window&quot;, WINDOW_AUTOSIZE );// Create a window for display.
    imshow( &quot;Display window&quot;, image );                   // Show our image inside it.

    waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
}"><pre class="notranslate"><code class="notranslate">#include &lt;opencv2/core/core.hpp&gt;
#include &lt;opencv2/highgui/highgui.hpp&gt;
#include &lt;iostream&gt;

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 &lt;&lt;  "Could not open or find the image" &lt;&lt; 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;
}
</code></pre></div>
<p dir="auto">This is my file structure in case it matters:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="├── data
    ├── example.jpg
└── src
    ├── BUILD
    ├── main.cpp"><pre class="notranslate"><code class="notranslate">├── data
    ├── example.jpg
└── src
    ├── BUILD
    ├── main.cpp
</code></pre></div>
<h3 dir="auto">Environment info</h3>
<p dir="auto">Operating System: Ubuntu 14.04.</p>
<p dir="auto">If installed from sources, provide the commit hash: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/tensorflow/tensorflow/commit/f952246b1756242926d47091d09ceb7c7b963269/hovercard" href="https://github.com/tensorflow/tensorflow/commit/f952246b1756242926d47091d09ceb7c7b963269"><tt>f952246</tt></a></p>
<h3 dir="auto">Steps to reproduce</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ python2 -c &quot;import tensorflow; import cv2; print cv2.imread('cat.jpg')&quot;
None"><pre class="notranslate">$ python2 -c <span class="pl-s"><span class="pl-pds">"</span>import tensorflow; import cv2; print cv2.imread('cat.jpg')<span class="pl-pds">"</span></span>
None</pre></div>
<h3 dir="auto">What have you tried?</h3>
<p dir="auto">import cv2 before tensorflow works.</p>
<p dir="auto">This problem also exists on CentOS 7. It doesn't happen on a latest ArchLinux.<br>
It's likely due to that tensorflow has it's own libjpeg that conflicts with opencv on some platforms.</p>