1

I'm trying to build a program in which I use gstreamer and opencv to manipulate images. This is my main file:

#include "GstSource.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui/highgui_c.h>  
#include <iostream>

static const int Key_Escape  =  27;

int main(int argc, char *argv[])
{
cv::namedWindow("Gstreamer");
cvMoveWindow("Gstreamer",100,100);

GstreamerPlayer player;
if (! player.open("videotestsrc") )
    std::cerr << "Unable to open pipeline" << std::endl;

if ( !player.setWidth(640) || !player.setHeight(480) ) {
    std::cerr << "Unable to change resolution" << std::endl;
    return 1;
}


bool fps_readed = false;
while (true) {
    if (!player.grabFrame()) {
        std::cerr << "Failed to grab frame" << std::endl;
        break;
    }
    GstreamerImage * frame = player.getImage();
    if (!frame) {
        std::cerr << "Failed to retrieve frame" << std::endl;
        break;
    }

    if (!fps_readed) {
        std::cout << "Video playing at " << player.getFps() << " fps" <    std::endl;
        fps_readed = true;
    }

    cv::Mat canvas = cv::Mat(frame->height, frame->width, CV_8UC3, frame->data);
    if ( canvas.empty() )
        break;
    cv::imshow("Gstreamer", canvas);

    int key = cv::waitKey(10);
    if (key == Key_Escape)
        break;
}
}

and this is the .pro file:

QT       += core

QT       -= gui

TARGET = provaQT
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

INCLUDEPATH += /usr/include/gstreamer-1.0 \
           /usr/local/include \
           /usr/include/glib-2.0 \
           /usr/lib/arm-linux-gnueabihf/glib-2.0/include \
           /usr/lib/arm-linux-gnueabihf

LIBS += -L"/usr/lib/arm-linux-gnueabihf" -lglib-2.0 -lgobject-2.0 \
    -L"/usr/local/lib" -lopencv_core -lopencv_highgui -lopencv_imgcodecs    -lopencv_imgproc -lopencv_videoio \
    -L"/usr/lib/arm-linux-gnueabihf/gstreamer-1.0" -lgnl -lgst1394 -lgstaasink -lgstaccurip -lgstcoreelements \
    -L"/home/odroid/Desktop/Gstreamer-Test/bin/linux/gst-plugins" -lgst-overlay


SOURCES += \
../Gstreamer-Test/src/gstinit.cpp \
../Gstreamer-Test/src/gstplugin.cpp \
../Gstreamer-Test/src/gstplugin_impl.cpp \
../Gstreamer-Test/src/GstSource.cpp \
../Gstreamer-Test/src/main.cpp \
../Gstreamer-Test/src/videotestoverlay.cpp

HEADERS += \
../Gstreamer-Test/src/gstplugin.hpp \
../Gstreamer-Test/src/gstplugin_impl.hpp \
../Gstreamer-Test/src/GstSource.hpp \
../Gstreamer-Test/src/videotestoverlay.hpp  

and I get 147 error of this type: undefined reference to..... because many function used are declared but not defined. Where are their definition? How I can include their definition?

1 Answers1

1

What about using PKGCONFIG:

in your pro:

CONFIG += pkgconfig
PKGCONFIG += gstreamer-1.0 gstreamer-video-1.0

You can check from shell that you have them:

pkg-config --list-all | grep gst

Checking one package if pointing to correct libraries:

pkg-config --cflags gstreamer-1.0

Should print:

-pthread -I/usr/local/include/gstreamer-1.0 -I/usr/local/lib/gstreamer-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -L/usr/local/lib -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0

If you do not have the .pc files they wont be listed.. You need to install the -dev version of the gstreamer packages.

Also there is env variable which can be used to tell pkg config where to look for .pc files:

PKG_CONFIG_PATH=/home/something/gst/1.6/gst-devtools/validate/pkgconfig

Here someone tried to link opencv that way..

Community
  • 1
  • 1
nayana
  • 3,787
  • 3
  • 20
  • 51
  • Thank you! I've followed your advice, but the problem still remains. Checking on the terminal I have obtained this: – P. Francesco Jun 10 '16 at 13:04
  • pkg-config --cflags gstreamer-1.0 -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include – P. Francesco Jun 10 '16 at 13:05
  • sorry, I have problems with enter button :) I have also verified that pkg-config list has gstreamer. Do you think it's a problem that my -pthread has less directories than yours? – P. Francesco Jun 10 '16 at 13:07
  • -pthread stands for libpthread .. you can use shift+enter .. hm, I think you are missing plugins include? I have quite a custom compiled gstreamer so I am not sure if we can compare our pkg configs.. – nayana Jun 10 '16 at 13:31
  • Well, when I am using a pipeline from command line it works... so I think it is a problem related to an uncorrect inclusion of libraries in qtcreator... maybe I can try with PKG_CONFIG_PATH... where can I add this path? Thanck u – P. Francesco Jun 10 '16 at 14:11
  • @P.Francesco try adding (this is per project) at Projects > Build tab > Build env, or in a wors case in .basrhc and run qtcreator from bash.. – nayana Jun 13 '16 at 13:27