Ask Your Question

ririgo's profile - activity

2021-01-18 19:03:30 -0600 received badge  Famous Question (source)
2020-10-27 16:15:59 -0600 received badge  Popular Question (source)
2019-11-22 09:34:28 -0600 received badge  Notable Question (source)
2019-08-15 16:11:17 -0600 received badge  Popular Question (source)
2018-03-08 10:51:53 -0600 asked a question H264 byte array to cv::Mat image in cpp

H264 byte array to cv::Mat image in cpp Hi, I'm trying to get frames from Parrot Bebop2 video stream. I can get H264 byt

2017-09-11 02:19:18 -0600 marked best answer Writing cv::Mat data is failed

Hi, I'm trying to read and write the data array of a cv::Mat only as a binary file. I saved the array like below.

FILE *file = fopen(file_name, "wb");
fwrite(mat.data, sizeof(char), height * width * 3, file); // RGB image
fclose(file);

Then I read it like below.

FILE *file2 = fopen(file_name, "rb");
fread(data, sizeof(char), height * width * 3, file2);
fclose(file2);
cv::Mat image(height, width, CV_8UC3, data);

It's fine when I check the result like this.

std::cout << data[height * width * 3 - 1] << image.at<cv::Vec3b>(height - 1, width - 1) << std::endl;

The last value of the "data" array and the red value of the last pixel of the cv::Mat image was the same. (ex, 37[41, 32, 37]) However, after I write the cv::Mat image again, the some pixel values are...destoyed like below. (ex, [127, 0, 0])

cv::imwrite(path, image);
cv::Mat test = cv::imread(path);
std::cout << test.at<cv::Vec3b>((height - 1, width - 1)) << std::endl;

The most of the pixels are OK but usually some of the last pixels are destroyed. Did I something wrong? Also, I read the binary file and save it as a image file using python cv2, that was OK. What should I do in C++?

2017-09-10 10:12:58 -0600 commented question Writing cv::Mat data is failed

Oh, thank you all for your answering. I tested my code on another ubuntu server, it works well.

2017-09-09 06:45:15 -0600 commented question Writing cv::Mat data is failed

Is there any way to read the data written already? I think it is not the problem of the written data because it has no p

2017-09-09 06:17:16 -0600 edited question Writing cv::Mat data is failed

Writing cv::Mat data is failed Hi, I'm trying to read and write the data array of a cv::Mat only as a binary file. I sav

2017-09-09 06:17:02 -0600 commented question Writing cv::Mat data is failed

Alright, another typo again, sorry.

2017-09-09 05:01:54 -0600 commented question Writing cv::Mat data is failed

I called cvtcolor (rgba to rgb) first before writing the binary file. Will it be a problem?

2017-09-09 04:58:03 -0600 commented question Writing cv::Mat data is failed

I called cvtcolor (rgba to rgb) first before writing. Will it be a problem?

2017-09-09 03:57:30 -0600 commented question Writing cv::Mat data is failed

Oh, it was a typo, sorry. I did it using fwrite.

2017-09-09 03:57:13 -0600 commented question Writing cv::Mat data is failed

@StevenPuttemans Oh, it was a typo, sorry. I did it using fwrite.

2017-09-09 03:53:51 -0600 edited question Writing cv::Mat data is failed

Writing cv::Mat data is failed Hi, I'm trying to read and write the data array of a cv::Mat only as a binary file. I sav

2017-09-09 03:53:41 -0600 commented question Writing cv::Mat data is failed

Oh, it was a typo, sorry. I did it using fwrite.

2017-09-09 03:25:29 -0600 edited question Writing cv::Mat data is failed

Writing cv::Mat data is failed Hi, I'm trying to read and write the data array of a cv::Mat only as a binary file. I sav

2017-09-09 03:24:25 -0600 asked a question Writing cv::Mat data is failed

Writing cv::Mat data is failed Hi, I'm trying to read and write the data array of a cv::Mat only as a binary file. I sav

2017-06-06 16:48:15 -0600 asked a question Corrupt JPEG data error when using yuyv webcam

Hi, I'm using yuyv format webcams. Here is my code.

#include <iostream>

#include <opencv2/opencv.hpp>
#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>

#define FPS 30
using namespace std;

int main(int argc, char** argv){
    std::cout << "stereo_cam_node" << std::endl;

    ros::init(argc, argv, "stereo_cam");
    ros::NodeHandle node;

    cv::VideoCapture left_capture(1);
    cv::VideoCapture right_capture(0);

    if(!left_capture.isOpened() && !right_capture.isOpened()){
        std::cerr << "Cameras are not working" << std::endl;
        return 0;
    }

    while(ros::ok()){
        cv::Mat left_mat, right_mat;
        left_capture >> left_mat;
        right_capture >> right_mat;

        cv::imshow("left", left_mat);
        cv::imshow("right", right_mat);

        cv::waitKey(10);
    }
    return 0;
}

It seems to works well with imshow GUI but the terminal says that

stereo_cam_node
Corrupt JPEG data: 6 extraneous bytes before marker 0x8a
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
init done
Corrupt JPEG data: 3 extraneous bytes before marker 0x8a
Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
Corrupt JPEG data: 3 extraneous bytes before marker 0xd9
Corrupt JPEG data: 2 extraneous bytes before marker 0xd9
Corrupt JPEG data: 4 extraneous bytes before marker 0x40
Corrupt JPEG data: 3 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0x4a
Corrupt JPEG data: 1727 extraneous bytes before marker 0xd9
Corrupt JPEG data: 1 extraneous bytes before marker 0x8a
Corrupt JPEG data: 5 extraneous bytes before marker 0x25
Corrupt JPEG data: 1905 extraneous bytes before marker 0x74
Corrupt JPEG data: 280 extraneous bytes before marker 0xd9

Shall I just ignore these messages or should I fix something? Also, I installed OpenCv 3.2 on NVIDIA Jetson TX1 with

cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_PNG=OFF \
    -DBUILD_TIFF=OFF \
    -DBUILD_TBB=OFF \
    -DBUILD_JPEG=OFF \
    -DBUILD_JASPER=OFF \
    -DBUILD_ZLIB=OFF \
    -DBUILD_EXAMPLES=ON \
    -DBUILD_opencv_java=OFF \
    -DBUILD_opencv_python2=ON \
    -DBUILD_opencv_python3=OFF \
    -DENABLE_PRECOMPILED_HEADERS=OFF \
    -DWITH_OPENCL=OFF \
    -DWITH_OPENMP=OFF \
    -DWITH_FFMPEG=ON \
    -DWITH_GSTREAMER=OFF \
    -DWITH_GSTREAMER_0_10=OFF \
    -DWITH_CUDA=ON \
    -DWITH_GTK=ON \
    -DWITH_VTK=OFF \
    -DWITH_TBB=ON \
    -DWITH_1394=OFF \
    -DWITH_OPENEXR=OFF \
    -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \
    -DCUDA_ARCH_BIN=5.3 \
    -DCUDA_ARCH_PTX="" \
    -DINSTALL_C_EXAMPLES=ON \
    -DINSTALL_TESTS=OFF \
    -DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \
    ..
2017-05-22 03:48:18 -0600 commented question initUndistortRectifyMap method throws segmentation fault

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.

2017-05-22 02:08:09 -0600 commented question initUndistortRectifyMap method throws segmentation fault

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

2017-05-22 01:41:40 -0600 received badge  Editor (source)
2017-05-22 01:39:50 -0600 commented question initUndistortRectifyMap method throws segmentation fault

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)

2017-05-22 01:21:18 -0600 asked a question initUndistortRectifyMap method throws segmentation fault

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}
)
2017-05-22 01:19:01 -0600 received badge  Enthusiast
2017-05-18 03:50:24 -0600 asked a question Does imwirte function write an image in RGB order?

Hi, I'm studying openCV and I have a simple question. I read a RGB image and I notice that openCV store it as a Mat in BGR oder. I wanna know whether the image file is in RGB order or BGR order, if I save the mat as a png file using imwrite.

2017-04-20 19:14:13 -0600 commented answer How can I register a keyboard event handier for opencv viz

I testes it but it didn't work for arrow keys. Of course I don't need to use arrow keys but is there any way to use arrow keys?

2017-04-20 19:11:54 -0600 commented answer How can I register a keyboard event handier for opencv viz

Thank you so much.

2017-04-20 04:09:43 -0600 received badge  Student (source)
2017-04-20 02:52:14 -0600 asked a question How can I register a keyboard event handier for opencv viz

Hi, I'm using opencv viz library to visualize 3D point clouds. I want to move the camera when I press an arrow key, but I can't find any example for it. Please help me.

2017-03-28 03:43:41 -0600 commented answer How can I get index of the gratest element in a Mat

Should I reshape a 2D Mat into a 1D Mat to use this solution?

2017-03-28 03:33:25 -0600 marked best answer How can I get index of the gratest element in a Mat

I know that opencv has sort method, but I want to get something like argmax method. How can I get indices of the gratest element, and second, an third, and so on, from a 2D Mat?

2017-03-28 03:32:13 -0600 marked best answer Is there an easy way to get indices of zeros (value is zero)?

Hi, I'm using findEssentialMat method and trying to use the "mask" it gives. I know that there is a way to get non-zero elements' indices, but how can I get indices of elements that have zero as their values?