rafaelsr
Posts: 1
Joined: Mon Oct 28, 2013 4:05 pm

OpenCV + Raspicam

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/593 ... 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 17534 times

RpiName
Posts: 614
Joined: Sat Jul 06, 2013 3:14 am

Re: OpenCV + Raspicam

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

nicodio
Posts: 2
Joined: Tue Nov 05, 2013 9:02 am

Re: OpenCV + Raspicam

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?

paulie
Posts: 259
Joined: Thu Jan 19, 2012 6:51 pm

Re: OpenCV + Raspicam

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

Redlime
Posts: 1
Joined: Fri May 09, 2014 10:31 pm

Re: OpenCV + Raspicam

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.

pageauc
Posts: 188
Joined: Fri Jan 04, 2013 10:52 pm

Re: OpenCV + Raspicam

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 ... peed-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

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 2 guests