Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when using tensorflow and tesseract together with opencv #260

Open
Kavan72 opened this issue Aug 19, 2021 · 6 comments
Open

Comments

@Kavan72
Copy link

Kavan72 commented Aug 19, 2021

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
@twistedfall
Copy link
Owner

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

@Kavan72
Copy link
Author

Kavan72 commented Aug 21, 2021

#[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

@twistedfall
Copy link
Owner

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.

@jackos
Copy link

jackos commented Jun 21, 2022

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.

@slavb18
Copy link

slavb18 commented Sep 15, 2022

hi @twistedfall
any news about this bug?

@twistedfall twistedfall changed the title weird error on imread! Segmentation fault when using tensorflow and tesseract together with opencv Oct 1, 2022
@twistedfall
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants