opencv-rust icon indicating copy to clipboard operation
opencv-rust copied to clipboard

Segmentation fault when using tensorflow and tesseract together with opencv

Open Kavan72 opened this issue 4 years ago • 6 comments

I'm getting segmentation fault (core dumped) while reading image from path using imread. i've noticed weird thing if i import tensorflow lib then only i'm getting this error

and if i remove imread code and just print tensorflow version using this line

print!("{}", tensorflow::version().unwrap());

then it's working fine

  1. Operating system => ubuntu 20.04
  2. The way you installed OpenCV: => apt package
  3. OpenCV version => 4.2.0
  4. rustc version => rustc 1.54.0 (a178d0322 2021-07-26)
       Fresh pkg-config v0.3.19
       Fresh autocfg v1.0.1
       Fresh unicode-xid v0.2.2
       Fresh cfg-if v1.0.0
       Fresh glob v0.3.0
       Fresh adler v1.0.2
       Fresh regex-syntax v0.6.25
       Fresh openssl-probe v0.1.4
       Fresh byteorder v1.4.3
       Fresh dunce v1.0.2
       Fresh percent-encoding v2.1.0
       Fresh once_cell v1.8.0
       Fresh maplit v1.0.2
       Fresh shlex v1.0.0
       Fresh vcpkg v0.2.15
       Fresh crc-catalog v1.1.1
       Fresh half v1.7.1
       Fresh crc v2.0.0
       Fresh libc v0.2.98
       Fresh proc-macro2 v1.0.28
       Fresh semver v1.0.4
       Fresh crc32fast v1.2.1
       Fresh jobserver v0.1.23
       Fresh quote v1.0.9
       Fresh memchr v2.4.0
       Fresh filetime v0.2.14
       Fresh xattr v0.2.2
       Fresh time v0.1.44
       Fresh socket2 v0.4.1
       Fresh protobuf v2.23.0
       Fresh rustversion v1.0.5
       Fresh cc v1.0.69
       Fresh syn v1.0.74
       Fresh miniz_oxide v0.4.4
       Fresh clang-sys v1.2.0
       Fresh aho-corasick v0.7.18
       Fresh num-traits v0.2.14
       Fresh thiserror-impl v1.0.26
       Fresh flate2 v1.0.20
       Fresh tar v0.4.35
       Fresh tensorflow-internal-macros v0.0.1 (https://github.com/tensorflow/rust.git#7c1d9c8e)
       Fresh thiserror v1.0.26
       Fresh regex v1.5.4
       Fresh clang v1.0.3
       Fresh num-complex v0.4.0
       Fresh libz-sys v1.1.3
       Fresh openssl-sys v0.9.65
       Fresh bzip2-sys v0.1.11+1.0.8
       Fresh bzip2 v0.4.3
       Fresh curl-sys v0.4.45+curl-7.78.0
       Fresh opencv-binding-generator v0.28.0 (https://github.com/twistedfall/opencv-rust.git#9bbcd64f)
       Fresh curl v0.4.38
       Fresh zip v0.5.13
       Fresh opencv v0.53.1 (https://github.com/twistedfall/opencv-rust.git#9bbcd64f)
       Fresh tensorflow-sys v0.20.0 (https://github.com/tensorflow/rust.git#7c1d9c8e)
       Fresh tensorflow v0.17.0 (https://github.com/tensorflow/rust.git#7c1d9c8e)
       Fresh load_model_in_rust v0.1.0 (/media/kavan/WORK/Self/load_model_in_rust)
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s

Kavan72 avatar Aug 19 '21 18:08 Kavan72

Can you please share the minimum code example that I can use to reproduce this issue?

twistedfall avatar Aug 21 '21 07:08 twistedfall

#[warn(unused_imports)]
#[warn(dead_code)]
use opencv::prelude::*;

use std::error::Error;

use tensorflow;

fn main() -> Result<(), Box<dyn Error>> {

    print!("{}", tensorflow::version().unwrap());

    let mut img = opencv::imgcodecs::imread(
        "/home/kavan/Downloads/test.jpeg", 
        opencv::imgcodecs::IMREAD_GRAYSCALE
    );

    Ok(())
}

here is my main.rs file

[package]
name = "load_model_in_rust"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tensorflow = { git = "https://github.com/tensorflow/rust.git" }
opencv = { git = "https://github.com/twistedfall/opencv-rust.git" }

here is my Cargo.toml file

Kavan72 avatar Aug 21 '21 15:08 Kavan72

I can confirm the issue, that's really weird indeed. It's reproducible using the repository version of OpenCV under Ubuntu 20.08, but I can't reproduce it on my local machine for example. There is even no need to call any tensorflow functions, just use tensorflow; is enough. I'll try to investigate it.

twistedfall avatar Aug 26 '21 11:08 twistedfall

I've run into this same issue on arch linux using the opencv from pacman, but if I build opencv myself and link that in it works fine.

jackos avatar Jun 21 '22 03:06 jackos

hi @twistedfall any news about this bug?

slavb18 avatar Sep 15 '22 09:09 slavb18

@slavb18 Not really, it's a very difficult thing to debug. Workaround by building the OpenCV from source should work

twistedfall avatar Oct 01 '22 07:10 twistedfall