initUndistortRectifyMap method throws segmentation fault [closed]

asked 2017-05-22 01:21:18 -0600

ririgo gravatar image

updated 2017-05-22 02:13:58 -0600

Hi, I'm using OpenCV 3.2. In Ubuntu 16 and ROS Kinetic, initUndistortRectifyMap method works well. However in Ubuntu 14 and ROS Indigo, initUndistortRectifyMap method throws segmentation fault. How can I solve this problem. Here my source code.

double left_K_array[9] = {597.1097521605675, 0.0, 347.63854815045744, 0.0, 596.4001364332671, 224.437236712643, 0.0, 0.0, 1.0};
double left_D_array[4] = {-0.4004496392598547, 0.19050457839257873, 0.00044124127310643773, -0.0028168245512799526};
double left_R_array[9] = {0.9999981271651781, -0.0012861392988823535, -0.0014462060157307741, 0.001273435625893902, 0.9999608983018283, -0.008751013033202502, 0.0014574044883866881, 0.008749154993737752, 0.9999606633558406};
double left_P_array[12] = {598.1045682828319, 0.0, 316.94952392578125, 0.0, 0.0, 598.1045682828319, 244.39208221435547, 0.0, 0.0, 0.0, 1.0, 0.0};

double right_K_array[9] = {598.6108688018368, 0.0, 298.3515214908845, 0.0, 599.2241883823533, 262.80305450499503, 0.0, 0.0, 1.0};
double right_D_array[4] = {-0.40413263574076447, 0.1948797724228192, 0.0005653616334116255, -0.004673877723474734};
double right_R_array[9] = {0.9999632630389491, 0.0015264370954696002, 0.008434605046514125, -0.0016001828733401033, 0.999960495231354, 0.0087434198936667, -0.008420925558926182, -0.008756595597529438, 0.9999262023000859};
double right_P_array[12] = {598.1045682828319, 0.0, 316.94952392578125, -70.87906420629835, 0.0, 598.1045682828319, 244.39208221435547, 0.0, 0.0, 0.0, 1.0, 0.0};

Mat left_K = Mat(3, 3, CV_64F, (void*)left_K_array);
Mat left_D = Mat(1, 4, CV_64F, (void*)left_D_array);
Mat left_R = Mat(3, 3, CV_64F, (void*)left_R_array);
Mat left_P = Mat(3, 4, CV_64F, (void*)left_P_array);

Mat right_K = Mat(3, 3, CV_64F, (void*)right_K_array);
Mat right_D = Mat(1, 4, CV_64F, (void*)right_D_array);
Mat right_R = Mat(3, 3, CV_64F, (void*)right_R_array);
Mat right_P = Mat(3, 4, CV_64F, (void*)right_P_array);

Mat cam1map1, cam1map2, cam2map1, cam2map2;
Size rectified_image_size = Size(640, 480);
    cout << "1" << endl;
initUndistortRectifyMap(left_K, left_D, left_R, left_P, rectified_image_size, CV_32FC1, cam1map1, cam1map2);
    cout << "2" << endl;
initUndistortRectifyMap(right_K, right_D, right_R, right_P, rectified_image_size, CV_32FC1, cam2map1, cam2map2);
    cout << "3" << endl;

The result is:

1
Segmentation fault (core dump)

The CMakeLists.txt file is here

cmake_minimum_required(VERSION 2.8.3)
project(depth_viewer)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra")

find_package(catkin REQUIRED COMPONENTS
    roscpp
    rospy
    sensor_msgs
    std_msgs
    image_transport
    cv_bridge
    message_generation
)

find_package(OpenCV 3 REQUIRED)

add_message_files(
    FILES
    stereo_image.msg
)

generate_messages(
    DEPENDENCIES
    std_msgs
    sensor_msgs
)

catkin_package(
#   INCLUDE_DIRS include
#   LIBRARIES stereocam
#   roscpp rospy sensor_msgs std_msgs
#   DEPENDS system_lib
)

include_directories(
    ${catkin_INCLUDE_DIRS}
    ${OpenCV_INCLUDE_DIRS}
    ~/vst_stereo_cam_driver/VSTSTCHW/
)

add_executable(stereocam_node src/stereocam_node.cpp)
target_link_libraries(stereocam_node
    ${catkin_LIBRARIES}
    ${OpenCV_LIBS}
    ~/vst_stereo_cam_driver/VSTSTCHW/libVSTSTCHW.so
)

add_executable(depth_viewer src/depth_viewer.cpp)
target_link_libraries(depth_viewer
    ${catkin_LIBRARIES}
    ${OpenCV_LIBS}
)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2017-05-22 03:58:56.961991

Comments

Using windows 10 and vs 2015 and opencv 3.2.0-dev no exception and no error. "initUndistortRectifyMap method throws segmentation fault" what is error messsage ? can you insert some cout before initUndistortRectifyMap and after ?

LBerger gravatar imageLBerger ( 2017-05-22 01:32:24 -0600 )edit
1

cout << "1" << endl; initUndistortRectifyMap(left_K, left_D, left_R, left_P, rectified_image_size, CV_32FC1, cam1map1, cam1map2); cout << "2" << endl; initUndistortRectifyMap(right_K, right_D, right_R, right_P, rectified_image_size, CV_32FC1, cam2map1, cam2map2); cout << "3" << endl;

than the result is: 1 Segmentation fault (core dump)

ririgo gravatar imageririgo ( 2017-05-22 01:39:50 -0600 )edit

On windows similar problem occurs when there is a mistmatch between debug and release lib. Is it possible in your project?

LBerger gravatar imageLBerger ( 2017-05-22 01:59:06 -0600 )edit

I built it using CMakeLists.txt file on Ubuntu 14. The file is added on the post.

ririgo gravatar imageririgo ( 2017-05-22 02:08:09 -0600 )edit

Your code is OK. Try to build and run using only opencv : void main(){your code}; without ROS only opencv and test it

LBerger gravatar imageLBerger ( 2017-05-22 02:59:28 -0600 )edit
1

Damn, I't works so well without ROS Indigo...thank you for your help. I think I need to find some way to use OpenCV 3 with ROS Indigo.

ririgo gravatar imageririgo ( 2017-05-22 03:48:18 -0600 )edit