OpenCV + Raspicam


6 posts
by rafaelsr » Tue Nov 26, 2013 12:57 pm
Hi everyone,

This is my first post on the forum so I hope you guys could help me.
I already have experience in development with OpenCV in another platforms, but It's the first time with Raspberry (Raspbian). I have followed some tutorials in order to install OpenCV in Raspbian to work with Raspicam (I'm using UV4L driver) and did it successfully (http://mitchtech.net/raspberry-pi-opencv/ and http://tothinkornottothink.com/post/59305587476/raspberry-pi-simplecv-opencv-raspicam-csi-camera).

So after that I tried to run a simple C++ example, that creates an OpenCV highgui window to display frames:

Code: Select all
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <vector>
#include <stdio.h>

using namespace cv;
using namespace std;

//hide the local functions in an anon namespace
namespace
{
    int process(VideoCapture& capture)
   {
      int n = 0;
        char filename[200];
        string window_name = "video | q or esc to quit";
        cout << "press space to save a picture. q or esc to quit" << endl;
       
        namedWindow(window_name, CV_WINDOW_KEEPRATIO); //resizable window;
       
        Mat frame, frameCopy;       
       
        for (;;)
        {
            capture >> frame;
           
            if (frame.empty())
                break;
               
            imshow(window_name, frame);
            char key = (char)waitKey(5); //delay N millis, usually long enough to display and capture input
           
            switch (key)
            {
            case 'q':
            case 'Q':
            case 27: //escape key
               return 0;
       
            case ' ': //Save an image
               sprintf(filename,"filename%.3d.jpg",n++);
               imwrite(filename,frame);
               cout << "Saved " << filename << endl;
               break;
       
            default:
               break;
            }
        }
        return 0;
    }

}

int main(int ac, char** av) {

    std::string arg = "0";   
    cout << "Program started..." << endl;
   
    VideoCapture capture(arg); //try to open string, this will attempt to open it as a video file
   
    if (!capture.isOpened()) //if this fails, try to open as a video camera, through the use of an integer param
        capture.open(atoi(arg.c_str()));
   
    if (!capture.isOpened()) {
        cerr << "Failed to open a video device or video file!\n" << endl;       
        return 1;
    }
   
    return process(capture);
}


I successfully compiled and built this code in Geany:
Compile: g++ -Wall $(pkg-config --cflags opencv) -c "%f"
Build: g++ -Wall $(pkg-config --libs opencv) -o "%e" "%f"

So far so good.
Problem is, when I execute this code, I get two windows. One that is desired and created in the code (namedWindow) and one that seems to be a native GPU window that is created when the VideoCapture object is opened. This window has almost the size of the entire screen and it's displayed in front of everything else, I can't move, resize or close this window.

Anyone have an idea of how can I get rid of this window? It is really bugging me out.
I'm sending a picture to illustrate the problem (I had to take a picture from my camera because print screen doesn't capture the GPU window).
Attachments
problem.jpg
Two windows problem
problem.jpg (55.2 KiB) Viewed 17133 times
Posts: 1
Joined: Mon Oct 28, 2013 4:05 pm
by RpiName » Tue Nov 26, 2013 6:12 pm
rafaelsr wrote:Hi everyone,
Anyone have an idea of how can I get rid of this window? It is really bugging me out.
I'm sending a picture to illustrate the problem (I had to take a picture from my camera because print screen doesn't capture the GPU window).


What about loading driver with the --nopreview option ? If you have an /etc/init.d/uv4l_raspicam.sh, then edit it and add --nopreview ,then restart the script.

See also:
Code: Select all
uv4l --driver raspicam --help --driver-help
Posts: 598
Joined: Sat Jul 06, 2013 3:14 am
by nicodio » Fri Nov 29, 2013 3:23 pm
Hi, I'm sorry if I don't answer your question but I'd like to ask you something.
I'm using opencv on the Raspberry and it works but I can't open any windows 'cause every time I call cvNamedWindow it gives me GdkGLExt-WARNING **: Window system doesn't support OpenGL.
Did I miss something?
Posts: 2
Joined: Tue Nov 05, 2013 9:02 am
by paulie » Tue Jan 28, 2014 7:07 pm
nicodio wrote:......... It gives me GdkGLExt-WARNING **: Window system doesn't support OpenGL.
Did I miss something?


I'm trying to run k3d (3D modeller) and get the same error followed by
ERROR: Could not initialize gtkglext

I have libraspberrypi0 and libgtkglext1 installed
It has been my custom to use Xeyes
Posts: 258
Joined: Thu Jan 19, 2012 6:51 pm
by Redlime » Fri May 09, 2014 10:35 pm
RpiName wrote:
rafaelsr wrote:Hi everyone,
Anyone have an idea of how can I get rid of this window? It is really bugging me out.
I'm sending a picture to illustrate the problem (I had to take a picture from my camera because print screen doesn't capture the GPU window).


What about loading driver with the --nopreview option ? If you have an /etc/init.d/uv4l_raspicam.sh, then edit it and add --nopreview ,then restart the script.

See also:
Code: Select all
uv4l --driver raspicam --help --driver-help


This worked after restarting the raspi.
Posts: 1
Joined: Fri May 09, 2014 10:31 pm
by pageauc » Sun Feb 07, 2016 9:34 pm
To resolve "GdkGLExt-WARNING **: Window system doesn't support OpenGL" problem
I have had the problem with my motion tracking https://github.com/pageauc/motion-track and speed camera https://github.com/pageauc/motion-track/tree/master/speed-track when displaying opencv windows on an attached display. The problem was with Rasbian Jessie but did not occur with Wheezy for some reason.
To Resolve the problem
Code: Select all
sudo apt-get update
sudo apt-get install libgl1-mesa-dri
Reboot for change to take effect then retest your problem app
Regards
Claude ...
GitHub - https://github.com/pageauc
YouTube - https://www.youtube.com/user/pageaucp
Posts: 179
Joined: Fri Jan 04, 2013 10:52 pm