简体   繁体   中英

Segmentation fault when using some OpenCV functions

This question might seem vague, but to be frank, that's all I've got and I'm unable to debug this issue as well.

I'm using Linux Mint and was using OpenCV for a long time now. Everything was working fine, until a few weeks back. Now, when I try to do some basic transformations, like transpose, or cvtColor, a segmentation fault pops up. I have really no idea when or how this started happening. Here is the minimal python script which returns me the error:

import cv2
im1 = cv2.imread("test.png", cv2.IMREAD_UNCHANGED)
im2 = cv2.cvtColor(im1, cv2.COLOR_RGBA2BGR)

I did the same in C++ as well, just in case:

#include <opencv2/imgproc/imgproc.hpp>                                          
#include <opencv2/highgui/highgui.hpp>                                          

int main() {                                                                    
    cv::Mat im1, im2;                                                           
    im1 = cv::imread("test.png", cv::IMREAD_UNCHANGED);                                               
    cv::cvtColor(im1, im2, cv::COLOR_RGBA2BGR);                                 
    return 0;                                                                   
} 

Please note that I'm using COLOR_RGBA2BGR because the test.png file under consideration do have the alpha channel.

The same segmentation fault happens when I tried transpose() as well. This was in a different program I had written sometime back. The same program works flawlessly in another machine. I had always assumed this error could be something related to mismatches in image size or something, but unfortunately, its not.

I'm not sure what other functions returns this error. I have uninstalled OpenCV, built from source, installed again and still the error persists. The only option I feel is left for me is to fresh install the OS, but any form of help to debug this issue would be greatly appreciated.

This is probably not related to your OS, python nor C++. I recommend using gdb to trace back where the segfault occurs; that should point you in the right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM