Weird behaviour when linking libtensorflow_framework(1.4) with opencv

asked 2017-11-05 09:56:07 -0500

tham gravatar image

updated 2017-11-05 12:39:04 -0500

os : ubuntu16.04.1 compiler : g++ 5.4.0 20160609 opencv 3.3.1

Create an app with tensorflow c++ library and opencv, there are weird behaviour when I link opencv with libtensorflow_framework.so.

  1. imshow, protobuf version conflict

This program was compiled against version 2.6.1 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.4.0). Contact the program author for an update. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "/build/mir-O8_xaj/mir-0.26.3+16.04.20170605/obj-x86_64-linux-gnu/src/protobuf/mir_protobuf.pb.cc".)

  1. imwrite, the program suddenly end, no error messages at all

  2. imread, cannot read image(every image are empty)

Source codes

    //cannot read the image, always empty
    cv::Mat input_mat = cv::imread(argv[1], cv::IMREAD_COLOR);
    std::cout<<argv[1]<<", size:"<<input_mat.size()<<std::endl;

    cv::VideoCapture cap("video.mp4");
    if(!cap.isOpened()){
        std::cerr<<"cannot open video"<<std::endl;
        return -1;
    }

    cv::Mat frame;
    int index = 0;
    while(1){
        cap>>frame;
        if(frame.empty()){
            break;
        }

        //complain protobuf version imcompatible
        cv::imshow("frame", frame);
        cv::waitKey(30);        
        std::cout<<index++<<","<<frame.size()<<std::endl;
        //crash after calling imwrite
        cv::imwrite("imgs/img_" + std::to_string(index++) + ".jpg", frame);
    }
edit retag flag offensive close merge delete

Comments

Move this cv::imwrite between imshow and waitKey

supra56 gravatar imagesupra56 ( 2017-11-07 07:29:26 -0500 )edit