I have the following code:
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv/cv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat image(200, 200, CV_8UC3, Scalar(0, 255, 0));
namedWindow("Displayimage", CV_WINDOW_AUTOSIZE);
imshow("Displayimage", image);
int key = -1;
while (key!=27) {
key = waitKey(0);
cout << key << endl;
}
return 0;
}
When I run it on Windows (CodeBlocks + minGW) and press "Shift" -> nothing happens and give different codes for "a" and "A" --> Good
When I run it on Linux/Ubuntu (CodeBlocks + GCC) and press "Shift" -> it returns a code for the Shift key and does not allow me to press "SHIFT+a". It always return the same code for "a" and "A".
Do you have any idea?
Thanks,
The implementation of the cv::waitKey(int) function is quite dependent on the underlying UI framework. For windows OS, common window display frameworks include .Net, QT and MFC. While in Linux distributions, the window display frameworks usually include GTK, QT, VTK and etc. You can find different versions of waitKey(int) implementations is the highgui module of OpenCV source, and the gtk version seems not to handle keystrokes combination, it's handled by using GMutex. So if you want to handle key combinations, you might have to change your UI framework or modify the implementation, and recompile your OpenCV with the selected UI framework.
Related
I'm using sfml to write a game, and I thought that since I was working in Xcode I would make a Mac version and a windows version. In the mac verision I thought that it would be nice to take advantage of NSMenu to make a menu for the game. Here's what I've tried so far in a file called main.mm:
#include <iostream>
#import <AppKit/AppKit.h>
void Launch()
{
NSMenu* menu = [[NSMenu alloc] initWithTitle:#"string"];
}
int main()
{
std::cout << "Mac main\n";
Launch();
}
The code doesn't compile. Xcode doesn't show any errors in the code itself. Any idea why this doesn't work?
You must return from main. Also, you should call NSApplicationMain() if you are using AppKit. For games, this means that you write your game in C++, and you call the C++ code from Objective-C classes.
int main(int argc, char **argv)
{
std::cout << "Mac main\n";
return NSApplicationMain(argc, argv);
}
To call into your C++ code, I would create an application delegate and launch your C++ code from -applicationDitFinishLaunching:. You can create the application delegate in your main nib file, as well as your menus.
I don't know how to integrate with SFML. I would either use NSMenu and AppKit, or use SFML and avoid Objective C.
In windows I can maximize current window by keyboard shortcut Alt+space then x. When I working on command prompt, can I do same thing using commands (without using shortcuts)?
Simply I need to create a bat file , that make windows maximize after run that.
Edit:
I need to do this without restarting the command prompt. because restart lost the content of existing window.
I've not found any reliable way of doing it without a third party tool. So, if you have access to a c compiler, you can build your own
#define _WIN32_WINNT 0x0500
#include "windows.h"
int main(int argc, char **argv){
ShowWindow(
(HWND) GetConsoleWindow(),
argc > 1 ? atoi( argv[1] ) : SW_SHOWDEFAULT
);
return 0;
}
Tested with mingw/gcc. This code uses the ShowWindow api function to change the show state of the current console window (handle retrieved via GetConsoleWindow()). If compiled to showWindow.exe you can do
showWindow.exe 3 to maximize the window
showWindow.exe 6 to minimize the window
showWindow.exe to return to default mode
See the api documentation for the full list of allowed values.
i think you'll have to check for additional software like autoit or
CMDOW
I have a global enumeration
enum class CColour{
BLACK,
WHITE,
GOLD
};
that has its own headerfile CColour.h wich is included in stdafx.h
I was trying to fix some bugs (EDIT: I'm done with that) and encountered the following:
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
[...]
CColour colour1 = WHITE;
[...]
}
I've set a watch to colour1 in Visual Studio, and I have some other functions using CColour too, but in the watch it is always displayed as <undefined value> with no type specifier. (and a small lock next to the icon, don't know if that's relevant)
this seems strange because every function that uses CColour works perfectly fine.
can anybody explain why that is and how to fix it?
I'm developing a Qt 4.8.4 GUI application targeting Windows 7. I'm trying to implement the "Solving a Problem Step by Step" approach to keep the GUI responsive during a long-running computation, which is nicely divisible into many small steps.
Here is a minimal working example of this technique:
Computation.h
#pragma once
#include "QtCore/QCoreApplication"
#include "QtCore/QDebug"
#include "QtCore/QObject"
#include "QtCore/QTimer"
class Computation : public QObject {
Q_OBJECT
public:
Computation() : amount_(0) {}
public Q_SLOTS:
void start() {
amount_ = 100000;
QTimer::singleShot(0, this, SLOT(calculate()));
}
private Q_SLOTS:
void calculate() {
if (--amount_ > 0) {
qDebug() << "Calculating..." << amount_;
//QCoreApplication::processEvents();
QTimer::singleShot(0, this, SLOT(calculate()));
} else {
qDebug() << "Finished";
}
}
private:
int amount_;
};
main.cpp
#include "Computation.h"
#include "QtCore/QDebug"
#include "QtGui/QApplication"
#include "QtGui/QMainWindow"
#include "QtGui/QPushButton"
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
Computation computation;
QMainWindow window;
QPushButton button(&window);
button.setText("Test");
QObject::connect(&button, SIGNAL(clicked()), &computation, SLOT(start()));
window.show();
return app.exec();
}
There's also a CMakeLists.txt for this example in case anyone wants to try it out.
Now, on to the actual problem: when the computation is running, certain GUI interactions lead to a lockup of the mouse. The cursor can still be moved, but clicking on any part of the desktop has no effect at all in this state. The computation still goes on. The only way to escape this lockup is to switch to another application with the keyboard (e.g. Alt+Tab, pressing the Windows key, or Ctrl+Alt+Del) or to wait until the computation has finished.
The GUI actions which lead to this state include attempting to move or resize the application's main window. Instead of changing the window's geometry, the mouse lockup explained above happens. However, the window instantaneously jumps to the position is was to supposed to be moved to as soon as the computation finishes (and you didn't switch to another window in between).
Opening the system menu (by clicking on the application symbol in the title bar) also leads to similar behavior, but this time only the application (including the system menu) is indifferent to mouse clicks.
I tried to work around this problem by issuing QCoreApplication::processEvents() in my calculate() method (commented line in the above example). This only helped a little: instead of locking up the mouse every time one tries to move or resize the window, you now have to do it about 3-5 times to trigger the behavior. Different combinations of QCoreApplication::sendPostedEvents() and QCoreApplication::flush() didn't help either.
How can I solve this problem? Is this a known Qt bug and/or is there a workaround?
If you need to make an application multi-threaded, you can use Qt's slots and signals architecture. Just emit a signal from your thread when something changes. Then in your UI thread, connect a slot to the signal from your thread:
Qt: Background thread refreshing UI thread
Using QThread is definitely a better strategy than chunking the computation and trying to do everything in one thread.
Then in the calculate thread, use a timer every 1/15 sec (for example) to call a signal that has been connected to a slot in the main thread, which informs the UI to update any data you want to see from the calculations.
I'm making a small plugin-kind-of graphics engine interface which uses OGRE internally. The idea is that a person creating a program in Windows or Linux, would be able to use my plugin for doing any graphics rendering they need to do.
In-fact there's already a Windows app using GDI & D3D calls to do drawing, which I need to modify so that it can use OGRE to do the drawing.
What puzzles me is that the app is programmed in VC++ and hence has Windows-style menus and client area for drawing. But since OGRE creates its own window for rendering, will it be possible for me to send a handle of the client area of the app's window to OGRE and will OGRE do all the drawing in the client area of the window?
I'm new to Windows programming and under a bit of a time constraint, so had to ask here.
maybe this can help:
Ogre::String winHandle;
#ifdef WIN32
// Windows code
winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId()));
#else
// Unix code
QX11Info info = x11Info();
winHandle = Ogre::StringConverter::toString((unsigned long)(info.display()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId()));
#endif
Ogre::NameValuePairList params;
params["parentWindowHandle"] = winHandle;
mOgreWindow = mOgreRoot->createRenderWindow( "QOgreWidget_RenderWindow",
this->width(),
this->height(),
false,
¶ms );
QX11Info is Qt class, used to get handle.
Handle is inserted to Ogre::NameValuePairList as name:"parentWindowHandle" value: your handle and ten sent as argument to OgreRoot::createRenderWindow(). I tried this code with Qt and it worked. If it wont work try to use externalWindowHandle as parameter name.
source: http://www.ogre3d.org/tikiwiki/QtOgre