This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM5728: Opencv threshold() crashed by libtbb.so

Part Number: AM5728


Tool/software: Linux

I am working on an application using opencv with "ti-processor-sdk-linux-rt-am57xx-evm-05.00.00.15", and I found the threshold() would be crashed by the libtbb.so(found this by coredump!). Then I replace it by that in "ti-processor-sdk-linux-rt-am57xx-evm-04.02.00.09", all is fine.

**BUT** there are some interesting things

1. While I run the application in the command line, the program crashed. While it managed by systemctl is fine.

2. the threshold() crashed when the input image is large(say 640x480), but it works fine when the input image is small(say 320x240)

here's my test code

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

int main() {
	cv::Mat img(640, 480, CV_8UC1);
	cv::Mat bin;

	cv::randu(img, 0, 255);
	std::cout << img << std::endl;

	cv::threshold(img, bin, 0, 255, cv::THRESH_OTSU | cv::THRESH_BINARY);

	std::cout << bin << std::endl;

	return 0;

}

I'm not sure whether is the bug in my application or in the implementation of opencv, Anyone can give me a hand? Thanks

REGARDS!

  • Hi,

    Sorry, I just came back to office today and couldn't get back to you earlier. I'll take a look and try with your application to see if I can reproduce the issue. I may come back with some questions on your environment.

    Thanks!

    Rex
  • Hi,

    I cross-compiled your code, and run on AM5728 EVM using SDK 5.0 release

    Linux Host:
    user:~/work/issues/opencv-threshold$ arm-linux-gnueabihf-g++ -I~/work/ti-processor-sdk-linux-am57xx-evm-05.00.00.15/linux-devkit/sysroots/armv7ahf-neon-linux-gnueabi/usr/include/opencv -I~/work/ti-processor-sdk-linux-am57xx-evm-05.00.00.15/linux-devkit/sysroots/armv7ahf-neon-linux-gnueabi/usr/include/opencv2 -L~/work/ti-processor-sdk-linux-am57xx-evm-05.00.00.15/linux-devkit/sysroots/armv7ahf-neon-linux-gnueabi/usr/lib -g -o test test.cpp -lrt -lopencv_core -lopencv_imgproc -lopencv_video -lopencv_videoio -lopencv_features2d -lopencv_imgcodecs

    ~/work/issues/opencv-threshold$ ls
    test test.cpp
    user:~/work/issues/opencv-threshold$ scp test root@158.218.116.200:/home/root/opecn_threshold
    test 100% 148KB 148.1KB/s 00:00
    user:~/work/issues/opencv-threshold$

    Target EVM:
    root@am57xx-evm:~/opencv_threshold_crash# uname -a
    Linux am57xx-evm 4.14.40-g4796173fc5 #1 SMP PREEMPT Wed Jul 25 17:05:51 UTC 2018 armv7l GNU/Linux

    I don't see any crash at all. I am not sure if I need image file. If it is needed, could you attach it in the thread?
    Below is a snippet of my logs when running your application:

    root@am57xx-evm:~# ls
    temp tibt opecn_threshold

    root@am57xx-evm:~# mkdir opencv_threshold_crash
    root@am57xx-evm:~# mv opecn_threshold opencv_threshold_crash/.
    root@am57xx-evm:~# cd opencv_threshold_crash
    root@am57xx-evm:~/opencv_threshold_crash# ls
    opecn_threshold
    root@am57xx-evm:~/opencv_threshold_crash# ./opecn_threshold
    [ 91, 2, 79, 179, 52, 205, 236, 8, 181, 239, 26, 248, 207, 218, 45, 183, 158, 101, 102, 18, 118, 68, 210, 139, 198, 207, 211, 181, 162, 197, 191, 196, 40, 7, 243, 230, 45, 6, 48, 173, 242, 125, 175, 90, 63, 90, 22, 112, 221, 167, 224, 113, 208, 123, 214, 35, 229, 6, 143, 138, 98, 81, 118, 187, 167, 140, 218, 178, 23, 43, 133, 154, 150, 76, 101, 8, 38, 238, 84, 47, 7, 117, 246, 163, 237, 69, 129, 60, 101, 41, 190, 50, 90, 72, 168, 109, 121, 220, 114, 248, 99, 202, 199, 212, 79, 128, 198, 90, 168, 76, 145, 181, 118, 8, 63, 114, 217, 164, 158, 217, 237, 147, 44, 207, 54, 182, 65, 197, 191, 239, 72, 166, 236, 240, 3, 151, 91, 246, 116, 238, 94, 63, 252, 232, 25, 17, 8, 166, 116, 81, 188, 16, 230, 22, 119, 167, 202, 216, 67, 81, 40, 12, 63, 223, 179, 10, 32, 65, 137, 135, 94, 29, 179, 116, 216, 88, 25, 178, 106, 162, 43, 237, 37, 69, 76, 108, 56, 145, 92, 130, 117, 176, 113, 246, 252, 120, 227, 208, 250, 253, 162, 183, 145, 236, 21, 21, 191, 13, 248, 132, 63, 137, 93, 95, 115, 52, 251, 83, 39, 121, 24, 194, 165, 45, 195, 212, 179, 56, 178, 241, 171, 93, 59, 234, 48, 161, 215, 116, 122, 74, 166, 67, 199, 42, 47, 21, 245, 89, 166, 132, 182, 100, 237, 217, 229, 208, 9, 55, 19, 48, 243, 235, 201, 51, 117, 198, 230, 106, 254, 241, 103, 164, 76, 91, 76, 2, 194, 166, 149, 151, 216, 43, 241, 173, 11, 152, 124, 187, 34, 183, 34, 248, 178, 183, 161, 247, 24, 174, 38, 96, 159, 225, 179, 83, 106, 152, 54, 158, 52, 19, 62, 74, 162, 28, 38, 115, 235, 203, 238, 133, 2, 129, 16, 126, 232, 154, 183, 78, 236, 22, 75, 70, 73, 220, 6, 181, 159, 13, 230, 114, 116, 241, 67, 28, 77, 85, 144, 181, 213, 109, 114, 37, 147, 123, 118, 239, 129, 45, 55, 67, 7, 177, 176, 121, 182, 243, 116, 15, 142, 35, 150, 81, 92, 131, 148, 173, 130, 147, 233, 144, 199, 180, 119, 245, 188, 18, 215, 198, 49, 185, 197, 230, 53, 187, 212, 7, 177, 90, 4, 0, 148, 79, 218, 89, 182, 107, 46, 181, 74, 71, 85, 57, 20, 167, 81, 106, 198, 210, 181, 247, 209, 234, 90, 81, 161, 70, 182, 138, 15, 251, 79, 209, 25, 132, 101, 237, 183, 242, 21, 79, 114, 218, 159, 52, 22, 155, 132, 235, 216, 68, 167, 242, 127, 211, 26, 160, 78, 77, 247, 148, 92, 51, 220, 251, 211, 120, 83, 39, 213, 211, 167, 66, 229, 214, 178, 131, 49, 2, 102, 241;
    210, 204, 3, 99, 162, 30, 35, 98, 130, 206, 254, 45, 254, 133, 31, 193, 57, 252, 190, 155, 82, 252, 51, 99, 168, 125, 176, 56, 183, 155, 42, 208, 36, 1, 88, 120, 44, 85, 186, 240, 152, 176, 98, 199, 167, 154, 160, 203, 185, 238, 36, 196, 31, 222, 90, 89, 177, 151, 26, 115, 88, 92, 99, 200, 144, 209, 199, 3, 245, 101, 171, 197, 147, 85, 21, 251, 68, 59, 62, 91, 171, 237, 11, 92, 177, 52, 44, 96, 108, 200, 15, 240, 76, 104, 67, 44, 103, 142, 142, 246, 240, 43, 138, 200, 137, 63, 178, 185, 141, 135, 52, 225, 186, 173, 74, 91, 172, 64, 95, 1, 45, 200, 204, 239, 85, 127, 112, 53, 184, 128, 142, 74, 24, 206, 253, 177, 135, 186, 145, 236, 237, 101, 193, 22, 171, 230, 200, 166, 248, 41, 127, 91, 12, 32, 208, 35, 208, 188, 21, 60, 175, 65, 198, 30, 63, 8, 151, 34, 188, 173, 217, 84, 70, 38, 174, 232, 74, 43, 98, 152, 179, 136, 0, 226, 134, 230, 131, 13, 82, 156, 97, 232, 63, 226, 172, 98, 59, 247, 161, 247, 201, 107, 62, 103, 172, 174, 55, 190, 89, 220, 88, 63, 254, 218, 206, 213, 34, 154, 140, 31, 33, 252, 237, 249, 27, 0, 109, 182, 3, 230, 234, 22, 10, 135, 165, 190, 219, 13, 147, 236, 163, 16, 40, 157, 238, 155, 47, 5, 27, 244, 213, 145, 26, 48, 83,

    I just realized that you are using RT-Linux. Since the work has been done, I may as well just post it and serve as the baseline. I'll create an RT-linux SD card and give it a try again.

    Rex
  • Hi,

    I can reproduce your issue using RT linux. Could you elaborate how you managed it using systemctl? I'd like to try it as well. Thanks!

    Rex
  • Hi,

    I am not convinced that there is an issue with RT Linux 5.0 release. Earlier I was able to reproduce the issue, but I noticed that there were errors with filesystem before running your application (see below), and I got core dump when running your application.

    am57xx-evm login: [ 35.607778] NET: Registered protocol family 15
    [ 35.729455] Initializing XFRM netlink socket
    [ 38.246055] EXT4-fs error (device mmcblk0p2): ext4_map_blocks:591: inode #93094: block 1279459328: comm matrix_browser: lblock 12 mapped to illegal pblock (length 1)
    [ 38.266733] EXT4-fs error (device mmcblk0p2): ext4_map_blocks:591: inode #93094: block 1279459328: comm matrix_browser: lblock 12 mapped to illegal pblock (length 1)
    root

    Then, I used a different SD card and re-imaged it. The filesystem came up clean on this one, and was successful running your application.

    root@am57xx-evm:~# uname -a
    Linux am57xx-evm 4.14.40-rt29-gd5443cbd3b #2 SMP PREEMPT RT Mon Jul 23 01:24:33 UTC 2018 armv7l GNU/Linux
    root@am57xx-evm:~# ./test
    [ 91, 2, 79, 179, 52, 205, 236, 8, 181, 239, 26, 248, 207, 218, 45, 183, 158, 101, 102, 18, 118, 68, 210, 139, 198, 207, 211, 181, 162, 197, 191, 196, 40, 7, 243, 230, 45, 6, 48, 173, 242, 125, 175, 90, 63, 90, 22, 112, 221, 167, 224, 113, 208, 123, 214, 35, 229, 6, 143, 138, 98, 81, 118, 187, 167, 140, 218, 178,

    When you got a crash, were you in the same situation as filesystem not coming up cleanly? If that is the case, please try using different SD card and be sure kernel boots up clean.

    Rex
  • Hi

    here is my systemctl service file

    [Unit]
    Description=my_app deamon
    Requires=aaaaa.service
    After=bbbbb.service
    
    
    [Service]
    Type=simple
    EnvironmentFile=enviroment_setting
    ExecStart=path_to_my_app_bin
    Restart=on-failure
    RestartSec=1s
    StandardOutput=null
    StandardError=inherit
    LimitCORE=infinity
    
    [Install]
    WantedBy=multi-user.target

  • Hi
    I will check this soon! thanks
  • Sure. If it solved your issue, please click "Resolved" button. Thanks!

    Rex
  • Hi, Rex

    Thanks for your help, the problem is solved! And I'm sorry that didn't tell you the full story.

    We ported the linux-rt to our custom board, whose file system starts with the "arago-base-tisdk-image-am57xx-evm.tar.xz" with some "needed" libs but the "libtbbmalloc.so, libtbbmalloc_proxy.so". After we added these libs, it works fine.