opencv :: Multiple unwanted window with Garbage name - c++

i am using opencv to capture video from webcam and display it in namedWindow.
cv::Mat rawImage;
cv::VideoCapture captureDevice;
captureDevice.open(0);
cv::namedWindow("webcam", 1);
bool running = true;
while(running)
{
captureDevice >> rawImage;
if(!rawImage.data)
{
continue;
}
cv::imshow("webcam", rawImage);
char ch = cv::waitKey(33);
if(ch == 'e')
running = false;
}
initially code runs fine but after random (5 sec approx) period older named window freezes and new window with some garbage name pops up and start showing webcam images. this continues to happen and i am getting multiple unwanted named window. What is the reason for popping up for those unwanted windows?

Have you tried the solution described here?
http://www.ridgesolutions.ie/index.php/2013/09/26/opencv-display-window-title-corrupted-and-multiple-windows-show/
They also indicate that they don't understand why, but that it was manually fixed by adding preprocessor definition _ITERATOR_DEBUG_LEVEL=0 to VS2012

Had the same issue with opencv 2410 and visual studio 2013 , window 7 64 bit.
Resolved when I linked debug libraries for debug configuration.
e.g. opencv_highgui2410d.lib

No waitkey() is existed in OpenCV, only waitKey() (maybe you have a typo here). Anyway, try to change
char ch = cv::waitkey(33);
to
char ch = cv::waitKey(33);
and test again. I have tested it on my PC (under VS2010), it worked fine.

Related

D3DERR_INVALIDCALL in d3d->CreateDevice causing window flicker on startup in Allegro 5 D3D program

I'm working on debugging window creation flicker when creating an Allegro 5 Direct3D window with multi sampling enabled. I've narrowed the problem down to window creation in allegro's d3d_disp.cpp source file. However, I can't get any debug output from DirectX. The flickering only happens in D3D mode (not OpenGL) and only when multi sampling is enabled. Also to note, this only happens when running the program on NVIDIA gpus, not on my integrated Intel.
I'm running Windows 10.
I've tried debugging this in Visual Studio 2017, but it doesn't capture debug output from DX. I installed the DirectX debug symbols when installing the DirectX SDK from June 2010.
I've tried rebuilding allegro and linking to libd3dx9d.a in gcc, but I still can't step into directx function calls and the symbols aren't loaded. There's no libd3d9d.a (note the d for debugging) library available, in MinGW-W64 GCC 8.1 or in the DirectX SDK from June 2010.
I tried running my program through PIX but it gives me an incompatibility error that I can't solve.
Here is testable example allegro 5 code :
#include <allegro5/allegro.h>
#include <allegro5/allegro_color.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_direct3d.h>
#include <cstdio>
#include <climits>
int main(int argc, char **argv) {
if (!al_init()) { return 1; }
al_init_primitives_addon();
al_install_keyboard();
ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
if (!queue) { return 2; }
al_register_event_source(queue, al_get_keyboard_event_source());
al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE);
al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);
bool use_opengl = false;
if (use_opengl) {
al_set_new_display_flags(ALLEGRO_OPENGL);
}
else {
al_set_new_display_flags(ALLEGRO_DIRECT3D);
}
ALLEGRO_DISPLAY *display = al_create_display(1024, 600);
if (!display) { return 2; }
if (use_opengl) {
al_set_window_title(display, "OpenGL window");
}
else {
al_set_window_title(display, "Direct3D window");
}
al_register_event_source(queue, al_get_display_event_source(display));
al_clear_to_color(al_color_name("black"));
al_draw_circle(500, 300, 200, al_color_name("white"), 5.0);
al_draw_line(200, 200, 700, 300, al_color_name("white"), 5.0);
al_flip_display();
bool quit = false;
while (!quit) {
ALLEGRO_EVENT ev;
al_wait_for_event(queue, &ev);
if (ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { quit = true; }
if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { quit = true; }
}
return 0;
}
Ideally, the window doesn't flicker upon creation. There are many many programs that use Direct3D that don't flicker on window creation.
I've narrowed down the problem to failed calls to d3d->CreateDevice returning D3DERR_INVALIDCALL on these lines in src\win\d3d_disp.cpp in allegro's source code here : https://github.com/liballeg/allegro5/blob/master/src/win/d3d_disp.cpp#L812-L837
I need help getting the debug output from DirectX, and nothing works so far. Any tips on debugging with DirectX9, VS 2017 (and/or) MinGW-W64 GCC 8.1 and GDB, or other methods is appreciated.
EDIT
An update on the things I've tried.
Defining D3D_DEBUG_INFO before including d3d9.h didn't seem to do anything when rebuilding allegro.
Enabling DirectX debugging output in the dxcpl did nothing.
Trying to run my app through PIX results in an incompatibility error. It says the directx subversions don't match between the app and the pix runtime. How do I build for a specific version of the DirectX dll?
I found that when multisampling is enabled through the D3D_PRESENT_PARAMETERS, the swap effect must be D3DSWAPEFFECT_DISCARD. Fixed that, nothing changed.
Still getting D3DERR_INVALIDCALL. I can't see anything in the presentation parameters that isn't initialized.
If I can't enable DirectX debug output I really can't tell why this error is occurring.
Debugging tips welcome. I can see that window creation fails multiple times before it succeeds and that is why the window flickers.
EDIT2
It seems to be a problem with the BackBufferFormat specified, as that is the only difference between successful window creation and failure.
EDIT3
The BackBufferFormat is fine. The real difference was the quality level of multi sampling being attempted. As per
https://github.com/liballeg/allegro5/blob/master/src/win/d3d_display_formats.cpp#L95
and
CheckDeviceMultiSampleType
there was an off by one error that made it attempt to set a quality level that was off by one. quality levels indicates the count, not the maximum index.
The flicker is gone but more testing needs to be done.
As for the supplementary question, how can I enable debug info with DirectX? Nothing I've done has worked as per the above. I will award the answer to anyone who can help me achieve debug output from D3D and DX.
#Gull_Code If you like, you can clone my testing fork of allegro here :
https://github.com/EdgarReynaldo/allegro5/tree/test
Bugsquasher
Each search I made on the topic returned the same 3 solutions:
-Bad driver, update or a downgrade
-Bad directx install, in the microsoft forums they asked the guy to uninstall directx, delete the root registry entry for it, reinstall directx
-A lot were pointing that it happens when the D3D struct is partially initialized without giving a fully initialized one...
I'll come back if I have some more informations.

Performance issues on different machines

I wrote a C++ program that uses opencv, I compiled it in VisualStudio 2010 using release mode as Win32 application, the opencv library is dynamically linked so I just copied the needed dll's to the root folder of the program(so I can run it on other computers), the program is tracking people in a video and works fine when I run it on my computer, however when I run it on other machines it works but 65% slower, at first I thought that its the machine it self that is slow, but then I wrote another small program(the code is below) whose only purpose is to read a video file and play it approximately at the original video speed. Unfortunately I have the same issue with it as well, it runs fine on my computer but when I run it on other computers it slows down by 65%(more or less), I am new to c++/opencv and I have no real idea why this is happening I'm hoping some one can enlighten me, was the dynamic linking a bad idea? and I should compile opencv as a static library(which I don't yet know how to do and will appreciate any help on the issue). or is it something else?
#include "opencv\cv.h"
#include "opencv\highgui.h"
int main(){
cv::VideoCapture vidBuffer;
if(!vidBuffer.open("res/test.mp4")){
std::cerr << "Cant find \"res/test.mp4\"\n";
system("pause");
return -1;
}
int fps = vidBuffer.get(CV_CAP_PROP_FPS);
int frameTime = 1000/fps;
//video loop
cv::Mat frame;
for(char c=-1;;c=cv::waitKey(frameTime)){
if(!vidBuffer.read(frame)||c==27)
break;
cv::imshow("Vidoe test", frame);
}
//loop emd
vidBuffer.release();
return 0;
}

SDL_RenderCopy() has strange behavior on Raspberry PI

This is driving me up the wall..
I've got a very simple SDL2 program.
It has a array of 3 SDL_Texture pointers.
These textures are filled as follows:
SDL_Texture *myarray[15];
SDL_Surface *surface;
for(int i=0;i<3;i++)
{
char filename[] = "X.bmp";
filename[0] = i + '0';
surface = SDL_LoadBMP(filename);
myarray[i] = SDL_CreateTextureFromSurface(myrenderer,surface);
SDL_FreeSurface(surface);
}
This works, no errors.
In the main loop (which is just a standard event loop waiting for SDL_QUIT, keystrokes and a user-event which a SDL_Timer puts in the event queue every second) I just do (for the timer triggered event):
idx = (idx+1) % 3; // idx is global var initially 0.
SDL_RenderClear(myrenderer);
SDL_RenderCopy(myrenderer, myarray[idx], NULL, NULL);
SDL_RendererPresent(myrenderer);
This works fine for 0.bmp and 1.bmp, but the 3rd image (2.bmp) simply shows as a black field.
This is structural.
If I alternate the first 2 images they are both fine.
If I alternate the 2nd and 3rd image the 3rd image doesn't show.
If I use more than 3 images then 3 and upwards show as black.
Loading order doesn't matter. It starts going wrong with the 3rd image loaded from disk.
All images are properly formatted BMP's.
I even saved 2.bmp back to disk under a different name by using SDL_SaveBMP() after it was loaded to make sure it got loaded in memory OK. The new file is bit for bit identical to the original.
This program, without modifications and the same bmp files, works fine on OSX (XCode5) and Windows (VC++ 2012 Express).
The problem only shows on the Raspberry PI.
I have placed explicit error checks on every call that can leave a result/error-code (not shown in the samples above for brevity) but all of them show "no error".
I have used the latest stable source set of www.libsdl.org and compiled as instructed (configure, make, make install, etc.).
Anybody got any idea what could be going on ?
P.S.
Keyboard input doesn't seem to work either on my PI, but I haven't delved into that yet.
Answering myself as I finally figured it out myself...
I finally went back to the README-raspberrypi.txt that came with the SDL2 sources.
I didn't read it carefully enough the first time around...
Problem 1: I'am running on a FULL-HD display. The PI's default GPU memory is 64MB which is not enough for large displays and double-buffering. As suggested in the README I increased this to 128MB and this solved the black image problem.
Problem 2: Text input wasn't working because my user-account was not in the input group. I had added the default "pi" account to the input group initially, but when I later started using another account I forgot to add that user to the group.
In short: Caught by my own (too) quick skimming of the documentation.

Function call causes C++ program to freeze unless stepped-through in debugger

I have this short C++ program which takes snapshot images from a camera in a loop and displays them:
void GenericPGRTest::execute()
{
// connect camera
Camera *cam = Camera::Connect();
// query resolution and create view window
const Resolution res = cam->GetResolution();
cv::namedWindow("View");
c = 0;
// keep taking snapshots until escape hit
while (c != 27)
{
const uchar *buf = cam->SnapshotMono();
// create image from buffer and display it
cv::Mat image(res.height, res.width, CV_8UC1, (void*)buf);
cv::imshow("Camera", image);
c = cv::waitKey(1000);
}
}
This uses a class (Camera) for camera control I created using the Point Grey SDK and functions from the OpenCV library to display the images. I'm not necessarily looking for answers relating to the usage of either of these libraries, but rather some insight on how to debug a bizarre problem in general. The problem is that the application freezes (not crashes) on the cam->SnapshotMono() line. Of course, I ran through the function with a debugger. Here is the contents:
const uchar* Camera::SnapshotMono()
{
cam_.StartCapture();
// get a frame
Image image;
cam_.RetrieveBuffer(&image);
cam_.StopCapture();
grey_buffer_.DeepCopy(&image);
return grey_buffer_.GetData();
}
Now, every time I step through the function in the debugger, everything works OK. But the first time I do a "step over" instead of "step into" SnapshotMono(), bam, the program freezes. When I pause it at that time, I notice that it's stuck inside SnapshotMono() at the RetrieveBuffer() line. I know it's a blocking call so it theoretically can freeze (no idea why but it's possible), but why does it block when running normally and not when being debugged? This is one of the weirdest kinds of behaviour under debugging I've seen so far. Any idea why this could happen?
For those familiar with FlyCapture, the code above doesn't break as is, but rather only when I use StartCapture() in callback mode, then terminate it with StopCapture() before it.
Compiled with MSVC2010, OpenCV 2.4.5 and PGR FlyCapture 2.4R10.
Wild guess ... but may it be that StartCapture already starts the process that
ends up with having the buffer in ìmage, and if you step you leave it some
time until you get to RetrieveBuffer. That's not the case if you run it all at once ...

OpenCV C++ crashes on close

I'm working on a simple background subtraction program by using OpenCV BackgroundSubtractorMOG2. The codes:
int main()
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat frame,foreground,image,edges;
BackgroundSubtractorMOG2 mog;
namedWindow("Capture", CV_WINDOW_AUTOSIZE);
namedWindow("Contours", CV_WINDOW_AUTOSIZE);
while(1)
{
cap >> frame; // get a new frame from camera
if( frame.empty() )
break;
image=frame.clone();
mog(frame,foreground,-1);
threshold(foreground,foreground,1,250,THRESH_BINARY);
medianBlur(foreground,foreground,9);
erode(foreground,foreground,Mat());
dilate(foreground,foreground,Mat());
imshow( "Capture",image );
imshow("Contours",foreground);
if(waitKey(30) >= 0) break;
}
}
The program works but upon exiting, an error will occur like this:Unhandled exception at 0xfeeefeee in {prog_name}.exe: 0xC0000005: Access violation reading location 0xfeeefeee. and it will point to crtexe.c on line 568:
if (has_cctor == 0)
_cexit();
Any idea what causes the problem? Thanks in advance.
PS: Currently using OpenCV 2.3.4 and VS C++ 2010 Exp. on Windows XP.
PSS: AFAIK each class/pointer including camera will be deinitialized/destroyed upon exit. Correct me if I wrong.
Updates(1): Still got the error, even after adding some lines into it.
Updates(2): Tried DEBUG for every line, still got nothing. Tried delete function to release resources but cannot find any pointer to use it with delete.
Updates(3): It seems like every video processing program I made using OpenCV C++ will crash on exit, even the one I copy-pasted from books/internet. Changed break with return -1, still crashes...
Updates(4): I tried my program on another PC (Ms VS 2010 Pro, Windows Vista 64b) and guess what, NO crash. Definitely something wrong with my computer's setup...