I tried to google my question in several website but it still no answer.
My problem is look like this http://opencv-users.1802565.n2.nabble.com/Runtime-error-for-createTrackbar-in-control-panel-td7550203.html
I tried to create the control panel in OpenCV window using Qt integration as show in an example of OpenCV Document: http://docs.opencv.org/modules/highgui/doc/qt_new_functions.html
By this function, it should be separate between image window (with 'imshow()') and control panel (with in other window, called control panel).
However, it is not work when run to the code 'createTrackbar(num1, NULL, &val1 , 255, NULL);' the error message 'Null pointer' is shown. However, if I change the parameter to the window name it is work!.
My code is like this:
#include <...opencv.hpp>
#include <...highgui.hpp>
char* num1 = "testTrack";
int val1 = 100;
const string mainwin = "show";
int main()
{
while (true)
{
frame = capture();
createTrackbar(num1, NULL, &val1 , 255, NULL);
process_frame = image_processing(frame);
imshow(mainwin, process_frame);
// [Exit the system]
if (condition)
break;
}
}
Do you have any idea?
I don't know if this answer is useful after all this time, but you need to use an empty string instead of a null pointer.
Try with:
createTrackbar(num1, "", &val1 , 255, NULL);
Related
I am attempting to load a wxIcon in Windows by loading from a system DLL (as the mime system told me that the icon for such a file type was in the DLL), eg.
wxIcon icon;
icon.LoadFile("C:\\WINDOWS\\system32\\zipfldr.dll", wxICON_DEFAULT_TYPE);
This fails but I was wondering if there was any way in the codebase of loading this, other than resorting to native Win32 functions.
Also, if there are native Win32 functions, does anyone know what they are?
EDIT: I have tried the following with no success:
::wxInitAllImageHandlers();
wxMimeTypesManager manager;
wxFileType* type = manager.GetFileTypeFromExtension("sys");
wxIconLocation location;
if (type->GetIcon(&location))
{
// location is something like C:\WINDOWS\system32\imageres.dll
wxIcon icon;
if (!icon.LoadFile(location.GetFileName(), wxBITMAP_TYPE_ICON /*I have tried wxICON_DEFAULT_TYPE too*/))
{
// Failed!
}
}
EDIT 2: In response to VZ, I have tried the following with no success sadly:
::wxInitAllImageHandlers();
wxMimeTypesManager manager;
wxFileType* type = manager.GetFileTypeFromExtension("sys");
wxIconLocation location;
if (type->GetIcon(&location))
{
// location is something like C:\WINDOWS\system32\imageres.dll,
//with an appropriate index as retrieved by location.GetIndex(), which is -67.
wxIcon icon(location);
if (!icon.IsOk())
{
BREAK;
// Failed!
}
}
EDIT 3:
Thanks for everyone's help - works fine if I use wxBITMAP_TYPE_ICO instead of wxBITMAP_TYPE_ICON (notice the N), and also I was putting my test code in my app's constructor instead of in ::OnInit. It worked in OnInit but not in the constructor so that's a lesson learned!
Thanks everyone for the help and speedy responses, much appreciated as always.
It should work if you specify type wxBITMAP_TYPE_ICO.
The first argument to LoadFile() must specify the icon resource ID when using wxBITMAP_TYPE_ICO (which is indeed what you need to use when loading icons from files, and not resources of the current module), i.e. you're also missing the ;N part at the end, where N is the value returned by wxFileTypeInfo::GetIconIndex().
But to avoid dealing with this explicitly, you should just use wxFileType::GetIcon() and construct wxIcon from the wxIconLocation filled in by it.
For example, this:
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 0d91f7fc75..3623aacc56 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
## -123,6 +123,12 ## bool MyApp::OnInit()
if ( !wxApp::OnInit() )
return false;
+ wxIcon icon(wxIconLocation(R"(c:\Windows\system32\imageres.dll)", -67));
+ if ( icon.IsOk() )
+ {
+ wxLogMessage("Loaded icon of size %d*%d", icon.GetWidth(), icon.GetHeight());
+ }
+
// create the main application window
MyFrame *frame = new MyFrame("Minimal wxWidgets App");
shows the expected message about loading the icon of size 32 by 32.
What would be the proper way to get the active window (the one with input focus) with XCB?
reply = xcb_get_input_focus_reply(connection, xcb_get_input_focus(connection), nullptr);
std::cout << "WId: " << reply->focus;
This seems to be work sometimes and sometimes not.
I also saw someone mentioned querying _NET_ACTIVE_WINDOW root window property but I can't figure out how that is done and is it always supported with XCB?
Edit: The approach above with xcb_get_input_focus is only one part, after getting the reply->focus, you need to follow up the parent windows via xcb_query_tree.
As far as I know, EWMH-compliant window managers are expected to set _NET_ACTIVE_WINDOW attribute of root window to the window ID of the currently active window.
In order to get it,
Use xcb_intern_atom to get the atom value for _NET_ACTIVE_WINDOW
Get the root window ID, e.g. using xcb_setup_roots_iterator(xcb_get_setup(connection)).data->root
Use xcb_get_property, xcb_get_property_reply, and xcb_get_property_value to get the value of the attribute of the root window.
_NET_ACTIVE_WINDOW has type of CARDINAL, which, for XCB purposes, has size of 32 bits.
Or you could use libxcb-ewmh which wraps this task into xcb_ewmh_get_active_window function.
This solution works for me, it's more or less migration from some X11 code to XCB. Basically get the focus window and follow up the the path of the parent window until the window id is equal to parent or root id, this is then the top level window.
WId ImageGrabber::getActiveWindow()
{
xcb_connection_t* connection = QX11Info::connection();
xcb_get_input_focus_reply_t* focusReply;
xcb_query_tree_cookie_t treeCookie;
xcb_query_tree_reply_t* treeReply;
focusReply = xcb_get_input_focus_reply(connection, xcb_get_input_focus(connection), nullptr);
xcb_window_t window = focusReply->focus;
while (1) {
treeCookie = xcb_query_tree(connection, window);
treeReply = xcb_query_tree_reply(connection, treeCookie, nullptr);
if (!treeReply) {
window = 0;
break;
}
if (window == treeReply->root || treeReply->parent == treeReply->root) {
break;
} else {
window = treeReply->parent;
}
free(treeReply);
}
free(treeReply);
return window;
}
as adding a ribbon button, I am also supplying the name for it. It is performing its desired action, but placement of string is absurd. It should not be over the image, but under it. Any suggestions please. Adding code snippet and screenshot.
RibbonButtonProp* mRibbonProperties;
bool m_bsetlargeimage = FALSE;
if (ButtonProp.Lookup(m_nMenuItemID, mRibbonProperties) != 0)
{
if (ButtonProp[m_nMenuItemID]->m_bIfSmallButton == FALSE)
{
m_PanelImage.SetImageSize(CSize(32, 32));
m_PanelImage.Load(ButtonProp[m_nMenuItemID]->m_nImageResourceId);
m_bsetlargeimage = TRUE;
}
else
{
m_PanelImage.SetImageSize(CSize(16, 16));
m_PanelImage.Load(ButtonProp[m_nMenuItemID]->m_nImageResourceId);
m_bsetlargeimage = FALSE;
}
pRibbonButton = new CMFCRibbonButton(m_nMenuItemID, m_strMenuItemName, m_PanelImage.ExtractIcon(ButtonProp[m_nMenuItemID]->m_nImageIndex));
pRibbonButton->SetAlwaysLargeImage(m_bsetlargeimage);
Print should be just under the image
There is no way to change this. This is the way ribbons are shown and drawn.
A button text in "large-mode" is always drawn below the icon. I see nothing in the code to change this behavior AND I would never change this, because it is the default behavior people want/expect to see in a standard ribbon.
Earlier
AddCategory(m_strMenuName, NULL, NULL, NULL, NULL, i, NULL);
Now
AddCategory(m_strMenuName, NULL, NULL, CSize(16,16), CSize(32, 32), i, NULL);
Explanation: It was placing the text assuming that all the image size is small only as it was not defined already while calling create.
I wrote a C++ software using GTK library (2.0 version) for UI.
The compilation (with makefile) gave no errors but when I execute the program the window appears empty.
I think I've done some error in the code that create the interface.
In particular I have some doubts about the widgets positioning and sizing.
The .h interface file is composed from the declaration of the struct widgets_t (that contains all the pointers to widgets of the interface) and the declaration of the function build_interface (that create and initialize the UI).
the .cpp interface file is
#include <gtk/gtk.h>
#include "interface.h"
void build_interface (widgets_t *widgets)
{
//window
widgets->W = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(widgets->W), "myNavigator");
gtk_window_set_default_size(GTK_WINDOW(widgets->W),800,600);
gtk_window_set_position(GTK_WINDOW(widgets->W), GTK_WIN_POS_NONE);
//menu bar
widgets->MB = gtk_menu_bar_new();
widgets->IF = gtk_menu_item_new_with_mnemonic("File");
gtk_menu_bar_append(GTK_MENU_BAR(widgets->MB), widgets->IF);
widgets->MF = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(widgets->IF), widgets->MF);
widgets->IQ = gtk_menu_item_new_with_mnemonic("Close");
gtk_menu_shell_append (GTK_MENU_SHELL (widgets->MF), widgets->IQ);
widgets->IM = gtk_menu_item_new_with_mnemonic("Map");
gtk_menu_bar_append(GTK_MENU_BAR(widgets->MB), widgets->IM);
widgets->MM = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(widgets->IM), widgets->MM);
widgets->ILM = gtk_menu_item_new_with_mnemonic("Load");
gtk_menu_shell_append (GTK_MENU_SHELL (widgets->MM), widgets->ILM);
widgets->IP = gtk_menu_item_new_with_mnemonic("Path");
gtk_menu_bar_append(GTK_MENU_BAR(widgets->MB), widgets->IP);
widgets->MP = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(widgets->IP), widgets->MP);
widgets->ICP = gtk_menu_item_new_with_mnemonic("Calculate");
gtk_menu_shell_append (GTK_MENU_SHELL (widgets->MP), widgets->ICP);
//image to display a map
widgets->I = gtk_image_new();
//widgets for input
widgets->LF = gtk_label_new("Origin:");
widgets->SBF = gtk_spin_button_new_with_range(0,0,1);
widgets->LT = gtk_label_new("Destination:");
widgets->SBT = gtk_spin_button_new_with_range(0,0,1);
//button to perform software elaboration
widgets->BCP = gtk_button_new_with_mnemonic("Calculate Path");
//containers
//vertical box
widgets->VB = gtk_vbox_new(false, 0);
gtk_box_pack_start(GTK_BOX(widgets->VB), widgets->LF, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(widgets->VB), widgets->SBF, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(widgets->VB), widgets->LT, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(widgets->VB), widgets->SBT, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(widgets->VB), widgets->BCP, FALSE, FALSE, 0);
//horizontal box
widgets->HB = gtk_hbox_new(false, 0);
gtk_box_pack_start(GTK_BOX(widgets->HB), widgets->MB, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(widgets->HB), widgets->I, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(widgets->HB), widgets->VB, FALSE, FALSE, 0);
//add vertical box to the window
gtk_container_add(GTK_CONTAINER(widgets->W), widgets->VB);
//display widgets
gtk_widget_show_all(widgets->W);
}
someone sees something wrong and helps me to appear the UI? :)
thank you all in advance!
As the comment says you failed parenting the widgets:
widgets->W should contain widgets->HB and not widgets->VB.
If you can run your program from a terminal (if you are on windows "cmd" should work), GTK should have warned you about wrong parenting when you added "VB" to "W".
Note also that you may want to use local declaration for intermediate objects like "vboxes", and also for objects that will not change during your program execution.
Also note that you can build the interface also in XML using glade or by hand through the GtkBuilder Interface.
IMHO programmatically built GUIs should be used only when the interface will need to change dinamically during the program execution.
I am using NCurses to try and get the desired output:
However with the following code:
int main(void)
{
WINDOW *white_space,*red_space,*blue_box;
int maxx,maxy;
initscr();
start_color();
init_pair(1,COLOR_WHITE,COLOR_BLUE);
init_pair(2,COLOR_RED,COLOR_WHITE);
init_pair(3,COLOR_BLACK,COLOR_GREEN);
init_pair(4,COLOR_RED,COLOR_RED);
white_space = subwin(stdscr,10,76,6,2);
red_space = subwin(stdscr,1,80,23,0);
getmaxyx(white_space,maxy,maxx);
blue_box = subwin(white_space,maxy-1,maxx-1,8,20);
if(white_space == NULL)
{
addstr("Unable to create subwindow\n");
endwin();
return 1;
}
bkgd(COLOR_PAIR(1));
addstr("Master window");
wbkgd(white_space,COLOR_PAIR(2));
mvwprintw(white_space, 0, 0, "%46s", "White space");
wbkgd(blue_box,COLOR_PAIR(4));
wbkgd(red_space,COLOR_PAIR(3));
waddstr(red_space,"Alert area");
wrefresh(white_space);
wrefresh(stdscr);
refresh();
getch();
endwin();
return 0;
}
I get the following output:
Is it possible to create a subwindow within a subwindow?
Thanks
ncurses (any non-buggy version of curses) supports subwindows, as noted in the manual.
In the given example, there are a few problems noticed:
white_space = subwin(stdscr,10,76,6,2);
red_space = subwin(stdscr,1,80,23,0);
getmaxyx(white_space,maxy,maxx);
blue_box = subwin(white_space,maxy-1,maxx-1,8,20);
For instance:
the initial size given to white_space does not take into account the actual screen-size (which could be narrower than 80 columns)
the size asked for blue_box is only slightly smaller than white_space, but starts far enough to the right that the window could not (in 80 columns) be shown. If so, no window is created.
There are several programs in ncurses-examples using subwin and the related derwin, which may be useful for comparison.