1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2023-06-01 09:37:38 +03:00
565 changed files with 84396 additions and 17589 deletions
+1 -10
View File
@@ -281,16 +281,7 @@ if(tgts STREQUAL "PRIVATE")
set(tgts "")
endif()
# install used dependencies only
if(NOT BUILD_SHARED_LIBS
AND NOT (CMAKE_VERSION VERSION_LESS "3.13.0") # upgrade CMake: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2152
)
foreach(tgt in ${tgts})
if(tgt MATCHES "^ocv\.3rdparty\.")
install(TARGETS ${tgt} EXPORT OpenCVModules)
endif()
endforeach()
endif()
ocv_install_used_external_targets(${tgts})
source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs})
source_group("Include" FILES ${highgui_ext_hdrs})
+1 -1
View File
@@ -20,7 +20,7 @@ if(WITH_GTK)
endif()
endif()
endif()
ocv_check_modules(GTHREAD gthread-2.0)
ocv_check_modules(GTHREAD gthread-2.0>=2.32)
if(HAVE_GTK AND NOT HAVE_GTHREAD)
message(FATAL_ERROR "gthread not found. This library is required when building with GTK support")
else()
+6 -4
View File
@@ -502,7 +502,7 @@ left scrolling, respectively.
@note
Mouse-wheel events are currently supported only on Windows.
Mouse-wheel events are currently supported only on Windows and Cocoa
@param flags The mouse callback flags parameter.
*/
@@ -518,16 +518,17 @@ Controls: use `space` or `enter` to finish selection, use key `c` to cancel sele
@param showCrosshair if true crosshair of selection rectangle will be shown.
@param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of
selection rectangle will correspont to the initial mouse position.
@param printNotice if true a notice to select ROI or cancel selection will be printed in console.
@return selected ROI or empty rect if selection canceled.
@note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...).
After finish of work an empty callback will be set for the used window.
*/
CV_EXPORTS_W Rect selectROI(const String& windowName, InputArray img, bool showCrosshair = true, bool fromCenter = false);
CV_EXPORTS_W Rect selectROI(const String& windowName, InputArray img, bool showCrosshair = true, bool fromCenter = false, bool printNotice = true);
/** @overload
*/
CV_EXPORTS_W Rect selectROI(InputArray img, bool showCrosshair = true, bool fromCenter = false);
CV_EXPORTS_W Rect selectROI(InputArray img, bool showCrosshair = true, bool fromCenter = false, bool printNotice = true);
/** @brief Allows users to select multiple ROIs on the given image.
@@ -541,12 +542,13 @@ use `esc` to terminate multiple ROI selection process.
@param showCrosshair if true crosshair of selection rectangle will be shown.
@param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of
selection rectangle will correspont to the initial mouse position.
@param printNotice if true a notice to select ROI or cancel selection will be printed in console.
@note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...).
After finish of work an empty callback will be set for the used window.
*/
CV_EXPORTS_W void selectROIs(const String& windowName, InputArray img,
CV_OUT std::vector<Rect>& boundingBoxes, bool showCrosshair = true, bool fromCenter = false);
CV_OUT std::vector<Rect>& boundingBoxes, bool showCrosshair = true, bool fromCenter = false, bool printNotice = true);
/** @brief Creates a trackbar and attaches it to the specified window.
+19 -13
View File
@@ -13,11 +13,14 @@ namespace
class ROISelector
{
public:
Rect select(const String &windowName, Mat img, bool showCrossair = true, bool fromCenter = true)
Rect select(const String &windowName, Mat img, bool showCrossair = true, bool fromCenter = true, bool printNotice = true)
{
// show notice to user
printf("Select a ROI and then press SPACE or ENTER button!\n");
printf("Cancel the selection process by pressing c button!\n");
if(printNotice)
{
// show notice to user
printf("Select a ROI and then press SPACE or ENTER button!\n");
printf("Cancel the selection process by pressing c button!\n");
}
key = 0;
imageSize = img.size();
@@ -83,16 +86,19 @@ class ROISelector
}
void select(const String &windowName, Mat img, std::vector<Rect> &boundingBoxes,
bool showCrosshair = true, bool fromCenter = true)
bool showCrosshair = true, bool fromCenter = true, bool printNotice = true)
{
printf("Finish the selection process by pressing ESC button!\n");
if(printNotice)
{
printf("Finish the selection process by pressing ESC button!\n");
}
boundingBoxes.clear();
key = 0;
// while key is not ESC (27)
for (;;)
{
Rect temp = select(windowName, img, showCrosshair, fromCenter);
Rect temp = select(windowName, img, showCrosshair, fromCenter, printNotice);
if (key == 27)
break;
if (temp.width > 0 && temp.height > 0)
@@ -195,21 +201,21 @@ class ROISelector
};
}
Rect cv::selectROI(InputArray img, bool showCrosshair, bool fromCenter)
Rect cv::selectROI(InputArray img, bool showCrosshair, bool fromCenter, bool printNotice)
{
ROISelector selector;
return selector.select("ROI selector", img.getMat(), showCrosshair, fromCenter);
return selector.select("ROI selector", img.getMat(), showCrosshair, fromCenter, printNotice);
}
Rect cv::selectROI(const String& windowName, InputArray img, bool showCrosshair, bool fromCenter)
Rect cv::selectROI(const String& windowName, InputArray img, bool showCrosshair, bool fromCenter, bool printNotice)
{
ROISelector selector;
return selector.select(windowName, img.getMat(), showCrosshair, fromCenter);
return selector.select(windowName, img.getMat(), showCrosshair, fromCenter, printNotice);
}
void cv::selectROIs(const String& windowName, InputArray img,
std::vector<Rect>& boundingBox, bool showCrosshair, bool fromCenter)
std::vector<Rect>& boundingBox, bool showCrosshair, bool fromCenter, bool printNotice)
{
ROISelector selector;
selector.select(windowName, img.getMat(), boundingBox, showCrosshair, fromCenter);
selector.select(windowName, img.getMat(), boundingBox, showCrosshair, fromCenter, printNotice);
}
+20 -7
View File
@@ -3021,25 +3021,38 @@ void DefaultViewPort::drawStatusBar()
// if (mouseCoordinate.x()>=0 && mouseCoordinate.y()>=0)
{
QRgb rgbValue = image2Draw_qt.pixel(mouseCoordinate);
const QPalette colorPalette{ QApplication::palette(this) };
if (nbChannelOriginImage==CV_8UC3 )
const QColor normalTextColor = colorPalette.brush(QPalette::WindowText).color();
const QString textColorName = normalTextColor.name();
if (nbChannelOriginImage==CV_8UC3)
{
centralWidget->myStatusBar_msg->setText(tr("<font color='black'>(x=%1, y=%2) ~ </font>")
const int r_half = normalTextColor.red() >> 1;
const int g_half = normalTextColor.green() >> 1;
const int b_half = normalTextColor.blue() >> 1;
const QColor red = QColor(255, g_half, b_half);
const QColor green = QColor(r_half, 255, b_half);
const QColor blue = QColor(r_half, g_half, 255);
centralWidget->myStatusBar_msg->setText(tr("<font color=%1>(x=%2, y=%3) ~ </font>")
.arg(textColorName)
.arg(mouseCoordinate.x())
.arg(mouseCoordinate.y())+
tr("<font color='red'>R:%3 </font>").arg(qRed(rgbValue))+//.arg(value.val[0])+
tr("<font color='green'>G:%4 </font>").arg(qGreen(rgbValue))+//.arg(value.val[1])+
tr("<font color='blue'>B:%5</font>").arg(qBlue(rgbValue))//.arg(value.val[2])
tr("<font color=%4>R:%5 </font>").arg(red.name()).arg(qRed(rgbValue))+
tr("<font color=%6>G:%7 </font>").arg(green.name()).arg(qGreen(rgbValue))+
tr("<font color=%8>B:%9</font>").arg(blue.name()).arg(qBlue(rgbValue))
);
}
if (nbChannelOriginImage==CV_8UC1)
{
//all the channel have the same value (because of cv::cvtColor(GRAY=>RGB)), so only the r channel is dsplayed
centralWidget->myStatusBar_msg->setText(tr("<font color='black'>(x=%1, y=%2) ~ </font>")
centralWidget->myStatusBar_msg->setText(tr("<font color=%1>(x=%2, y=%3) ~ </font>")
.arg(textColorName)
.arg(mouseCoordinate.x())
.arg(mouseCoordinate.y())+
tr("<font color='grey'>L:%3 </font>").arg(qRed(rgbValue))
tr("<font color='grey'>L:%4 </font>").arg(qRed(rgbValue))
);
}
}
+22 -3
View File
@@ -593,7 +593,7 @@ int waitKeyImpl (int maxWait)
inMode:NSDefaultRunLoopMode
dequeue:YES];
if([event type] == NSKeyDown) {
if([event type] == NSKeyDown && [[event characters] length]) {
returnCode = [[event characters] characterAtIndex:0];
break;
}
@@ -866,8 +866,22 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) {
mp.y *= (imageSize.height / std::max(viewSize.height, 1.));
mp.x *= (imageSize.width / std::max(viewSize.width, 1.));
if( mp.x >= 0 && mp.y >= 0 && mp.x < imageSize.width && mp.y < imageSize.height )
mouseCallback(type, mp.x, mp.y, flags, mouseParam);
if( [event type] == NSEventTypeScrollWheel ) {
if( event.hasPreciseScrollingDeltas ) {
mp.x = int(event.scrollingDeltaX);
mp.y = int(event.scrollingDeltaY);
} else {
mp.x = int(event.scrollingDeltaX / 0.100006);
mp.y = int(event.scrollingDeltaY / 0.100006);
}
if( mp.x && !mp.y && cv::EVENT_MOUSEWHEEL == type ) {
type = cv::EVENT_MOUSEHWHEEL;
}
mouseCallback(type, mp.x, mp.y, flags, mouseParam);
} else if( mp.x >= 0 && mp.y >= 0 && mp.x < imageSize.width && mp.y < imageSize.height ) {
mouseCallback(type, mp.x, mp.y, flags, mouseParam);
}
}
- (void)cvMouseEvent:(NSEvent *)event {
@@ -890,6 +904,11 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) {
if([event type] == NSLeftMouseDragged) {[self cvSendMouseEvent:event type:cv::EVENT_MOUSEMOVE flags:flags | cv::EVENT_FLAG_LBUTTON];}
if([event type] == NSRightMouseDragged) {[self cvSendMouseEvent:event type:cv::EVENT_MOUSEMOVE flags:flags | cv::EVENT_FLAG_RBUTTON];}
if([event type] == NSOtherMouseDragged) {[self cvSendMouseEvent:event type:cv::EVENT_MOUSEMOVE flags:flags | cv::EVENT_FLAG_MBUTTON];}
if([event type] == NSEventTypeScrollWheel) {[self cvSendMouseEvent:event type:cv::EVENT_MOUSEWHEEL flags:flags ];}
}
-(void)scrollWheel:(NSEvent *)theEvent {
[self cvMouseEvent:theEvent];
}
- (void)keyDown:(NSEvent *)theEvent {
//cout << "keyDown" << endl;
+50 -139
View File
@@ -57,10 +57,13 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <stdio.h>
#if (GTK_MAJOR_VERSION == 2)
#define GTK_VERSION2 1
#endif //GTK_MAJOR_VERSION >= 2.0
#if (GTK_MAJOR_VERSION == 3)
#define GTK_VERSION3 1
#endif //GTK_MAJOR_VERSION >= 3
#if (GTK_MAJOR_VERSION > 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 4))
#if (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 4)
#define GTK_VERSION3_4 1
#endif
@@ -195,7 +198,7 @@ cvImageWidget_realize (GtkWidget *widget)
attributes.y = allocation.y;
attributes.width = allocation.width;
attributes.height = allocation.height;
#else
#elif defined(GTK_VERSION2)
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
@@ -238,7 +241,7 @@ cvImageWidget_realize (GtkWidget *widget)
gtk_widget_get_window(widget),
GTK_STATE_ACTIVE
);
#else
#elif defined(GTK_VERSION2)
// The following lines are included to prevent breaking
// compatibility with older Gtk2 (<gtk+-2.18) libraries.
attributes.colormap = gtk_widget_get_colormap (widget);
@@ -309,8 +312,9 @@ cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gin
*natural_height = *minimal_height;
}
}
#endif //GTK_VERSION3
#else
#if defined (GTK_VERSION2)
static void
cvImageWidget_size_request (GtkWidget *widget,
GtkRequisition *requisition)
@@ -341,7 +345,7 @@ cvImageWidget_size_request (GtkWidget *widget,
}
//printf("%d %d\n",requisition->width, requisition->height);
}
#endif //GTK_VERSION3
#endif //GTK_VERSION2
static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_height){
CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget );
@@ -382,7 +386,7 @@ cvImageWidget_size_allocate (GtkWidget *widget,
#if defined (GTK_VERSION3)
gtk_widget_set_allocation(widget, allocation);
#else
#elif defined (GTK_VERSION2)
widget->allocation = *allocation;
#endif //GTK_VERSION3
image_widget = CV_IMAGE_WIDGET (widget);
@@ -415,7 +419,7 @@ cvImageWidget_size_allocate (GtkWidget *widget,
allocation->width = image_widget->original_image->cols;
allocation->height = image_widget->original_image->rows;
gtk_widget_set_allocation(widget, allocation);
#else
#elif defined (GTK_VERSION2)
widget->allocation.width = image_widget->original_image->cols;
widget->allocation.height = image_widget->original_image->rows;
#endif //GTK_VERSION3
@@ -467,13 +471,11 @@ static void cvImageWidget_class_init (gpointer g_class, gpointer /*class_data*/)
CvImageWidgetClass* klass = (CvImageWidgetClass*)g_class;
#if defined (GTK_VERSION3)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
#else
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass*) klass;
widget_class = (GtkWidgetClass*) klass;
#endif //GTK_VERSION3
#if defined (GTK_VERSION2)
GtkObjectClass *object_class = (GtkObjectClass*) klass;
GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
#endif //GTK_VERSION2
parent_class = GTK_WIDGET_CLASS( g_type_class_peek (gtk_widget_get_type ()) );
@@ -481,10 +483,11 @@ static void cvImageWidget_class_init (gpointer g_class, gpointer /*class_data*/)
widget_class->destroy = cvImageWidget_destroy;
widget_class->get_preferred_width = cvImageWidget_get_preferred_width;
widget_class->get_preferred_height = cvImageWidget_get_preferred_height;
#else
#endif //GTK_VERSION3
#if defined (GTK_VERSION2)
object_class->destroy = cvImageWidget_destroy;
widget_class->size_request = cvImageWidget_size_request;
#endif //GTK_VERSION3
#endif //GTK_VERSION2
widget_class->realize = cvImageWidget_realize;
widget_class->size_allocate = cvImageWidget_size_allocate;
@@ -665,14 +668,6 @@ int cv::startWindowThread(){
gtk_InitSystem(0,NULL);
if (!thread_started)
{
#if !GLIB_CHECK_VERSION(2, 32, 0) // https://github.com/GNOME/glib/blame/b4d58a7105bb9d75907233968bb534b38f9a6e43/glib/deprecated/gthread.h#L274
if (!g_thread_supported ())
{
/* the GThread system wasn't inited, so init it */
g_thread_init(NULL);
}
#endif
(void)getWindowMutex(); // force mutex initialization
// protects the 'last key pressed' variable
@@ -681,13 +676,7 @@ int cv::startWindowThread(){
// conditional that indicates a key has been pressed
cond_have_key = g_cond_new();
#if !GLIB_CHECK_VERSION(2, 32, 0)
// this is the window update thread
window_thread = g_thread_create(icvWindowThreadLoop,
NULL, TRUE, NULL);
#else
window_thread = g_thread_new("OpenCV window update", icvWindowThreadLoop, NULL);
#endif
}
thread_started = window_thread!=NULL;
return thread_started;
@@ -753,6 +742,11 @@ CvRect cvGetWindowRect_GTK(const char* name)
return cvRect(getImageRect_(window));
}
#if defined(GTK_VERSION2)
#define gtk_widget_get_allocated_width(widget) (widget->allocation.width)
#define gtk_widget_get_allocated_height(widget) (widget->allocation.height)
#endif
static Rect getImageRect_(const std::shared_ptr<CvWindow>& window)
{
CV_Assert(window);
@@ -761,28 +755,18 @@ static Rect getImageRect_(const std::shared_ptr<CvWindow>& window)
#ifdef HAVE_OPENGL
if (window->useGl) {
gtk_widget_translate_coordinates(window->widget, gtk_widget_get_toplevel(window->widget), 0, 0, &wx, &wy);
return Rect(wx, wy, window->widget->allocation.width, window->widget->allocation.height);
return Rect(wx, wy, gtk_widget_get_allocated_width(window->widget), gtk_widget_get_allocated_height(window->widget));
}
#endif
CvImageWidget * image_widget = CV_IMAGE_WIDGET( window->widget );
gtk_widget_translate_coordinates(&image_widget->widget, gtk_widget_get_toplevel(&image_widget->widget), 0, 0, &wx, &wy);
if (image_widget->scaled_image) {
#if defined (GTK_VERSION3)
return Rect(wx, wy, MIN(image_widget->scaled_image->cols, gtk_widget_get_allocated_width(window->widget)),
MIN(image_widget->scaled_image->rows, gtk_widget_get_allocated_height(window->widget)));
#else
return Rect(wx, wy, MIN(image_widget->scaled_image->cols, window->widget->allocation.width),
MIN(image_widget->scaled_image->rows, window->widget->allocation.height));
#endif //GTK_VERSION3
} else if (image_widget->original_image) {
#if defined (GTK_VERSION3)
return Rect(wx, wy, MIN(image_widget->original_image->cols, gtk_widget_get_allocated_width(window->widget)),
MIN(image_widget->original_image->rows, gtk_widget_get_allocated_height(window->widget)));
#else
return Rect(wx, wy, MIN(image_widget->original_image->cols, window->widget->allocation.width),
MIN(image_widget->original_image->rows, window->widget->allocation.height));
#endif //GTK_VERSION3
}
return Rect(-1, -1, -1, -1);
@@ -888,12 +872,8 @@ double cvGetRatioWindow_GTK(const char* name)
static double getRatioWindow_(const std::shared_ptr<CvWindow>& window)
{
#if defined (GTK_VERSION3)
double result = static_cast<double>(
gtk_widget_get_allocated_width(window->widget)) / gtk_widget_get_allocated_height(window->widget);
#else
double result = static_cast<double>(window->widget->allocation.width) / window->widget->allocation.height;
#endif // GTK_VERSION3
return result;
}
@@ -947,7 +927,7 @@ namespace
if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
CV_Error( CV_OpenGlApiCallError, "Can't Activate The GL Rendering Context" );
glViewport(0, 0, window->widget->allocation.width, window->widget->allocation.height);
glViewport(0, 0, gtk_widget_get_allocated_width(window->widget), gtk_widget_get_allocated_height(window->widget));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -965,8 +945,11 @@ namespace
#endif // HAVE_OPENGL
#if defined (GTK_VERSION3)
#if defined (GTK_VERSION2)
static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data)
#elif defined (GTK_VERSION3)
static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data)
#endif
{
#ifdef HAVE_OPENGL
CvWindow* window = (CvWindow*)data;
@@ -979,6 +962,9 @@ static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data
#else
(void)data;
#endif
#if defined (GTK_VERSION2)
(void)event;
#endif
CvImageWidget *image_widget = NULL;
GdkPixbuf *pixbuf = NULL;
@@ -987,108 +973,38 @@ static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data
g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE);
image_widget = CV_IMAGE_WIDGET (widget);
#if defined (GTK_VERSION2)
cairo_t *cr = gdk_cairo_create(widget->window);
#endif
if( image_widget->scaled_image ){
// center image in available region
#if defined (GTK_VERSION3)
int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2;
int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2;
#else
int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2;
int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2;
#endif //GTK_VERSION3
#if defined (GTK_VERSION3)
pixbuf = gdk_pixbuf_new_from_data(image_widget->scaled_image->data.ptr, GDK_COLORSPACE_RGB, false,
8, MIN(image_widget->scaled_image->cols, gtk_widget_get_allocated_width(widget)),
MIN(image_widget->scaled_image->rows, gtk_widget_get_allocated_height(widget)),
image_widget->scaled_image->step, NULL, NULL);
#else
pixbuf = gdk_pixbuf_new_from_data(image_widget->scaled_image->data.ptr, GDK_COLORSPACE_RGB, false,
8, MIN(image_widget->scaled_image->cols, widget->allocation.width),
MIN(image_widget->scaled_image->rows, widget->allocation.height),
image_widget->scaled_image->step, NULL, NULL);
#endif //GTK_VERSION3
gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0);
}
else if( image_widget->original_image ){
#if defined (GTK_VERSION3)
pixbuf = gdk_pixbuf_new_from_data(image_widget->original_image->data.ptr, GDK_COLORSPACE_RGB, false,
8, MIN(image_widget->original_image->cols, gtk_widget_get_allocated_width(widget)),
MIN(image_widget->original_image->rows, gtk_widget_get_allocated_height(widget)),
image_widget->original_image->step, NULL, NULL);
#else
pixbuf = gdk_pixbuf_new_from_data(image_widget->original_image->data.ptr, GDK_COLORSPACE_RGB, false,
8, MIN(image_widget->original_image->cols, widget->allocation.width),
MIN(image_widget->original_image->rows, widget->allocation.height),
image_widget->original_image->step, NULL, NULL);
#endif //GTK_VERSION3
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
}
cairo_paint(cr);
if(pixbuf)
g_object_unref(pixbuf);
return TRUE;
}
#else
static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data)
{
#ifdef HAVE_OPENGL
CvWindow* window = (CvWindow*)data;
if (window->useGl)
{
drawGl(window);
return TRUE;
}
#else
(void)data;
#endif
CvImageWidget *image_widget = NULL;
cairo_t *cr = NULL;
GdkPixbuf *pixbuf = NULL;
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
if (event->count > 0)
return FALSE;
cr = gdk_cairo_create(widget->window);
image_widget = CV_IMAGE_WIDGET (widget);
if( image_widget->scaled_image ){
// center image in available region
int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2;
int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2;
pixbuf = gdk_pixbuf_new_from_data(image_widget->scaled_image->data.ptr, GDK_COLORSPACE_RGB, false,
8, MIN(image_widget->scaled_image->cols, widget->allocation.width),
MIN(image_widget->scaled_image->rows, widget->allocation.height),
image_widget->scaled_image->step, NULL, NULL);
gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0);
}
else if( image_widget->original_image ){
pixbuf = gdk_pixbuf_new_from_data(image_widget->original_image->data.ptr, GDK_COLORSPACE_RGB, false,
8, MIN(image_widget->original_image->cols, widget->allocation.width),
MIN(image_widget->original_image->rows, widget->allocation.height),
image_widget->original_image->step, NULL, NULL);
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
}
cairo_paint(cr);
if(pixbuf)
g_object_unref(pixbuf);
#if defined (GTK_VERSION2)
cairo_destroy(cr);
#endif
return TRUE;
}
#endif //GTK_VERSION3
static std::shared_ptr<CvWindow> namedWindow_(const std::string& name, int flags);
@@ -1761,20 +1677,20 @@ static void icvShowSaveAsDialog(GtkWidget* widget, CvWindow* window)
}
}
#if defined (GTK_VERSION3)
#define GDK_Escape GDK_KEY_Escape
#define GDK_Return GDK_KEY_Return
#define GDK_Linefeed GDK_KEY_Linefeed
#define GDK_Tab GDK_KEY_Tab
#define GDK_s GDK_KEY_s
#define GDK_S GDK_KEY_S
#endif //GTK_VERSION3
#if defined(GTK_VERSION2) && !defined (GDK_KEY_Escape)
#define GDK_KEY_Escape GDK_Escape
#define GDK_KEY_Return GDK_Return
#define GDK_KEY_Linefeed GDK_Linefeed
#define GDK_KEY_Tab GDK_Tab
#define GDK_KEY_s GDK_s
#define GDK_KEY_S GDK_S
#endif //GDK_KEY_Escape
static gboolean icvOnKeyPress(GtkWidget* widget, GdkEventKey* event, gpointer user_data)
{
int code = 0;
if ( BIT_ALLIN(event->state, GDK_CONTROL_MASK) && (event->keyval == GDK_s || event->keyval == GDK_S))
if ( BIT_ALLIN(event->state, GDK_CONTROL_MASK) && (event->keyval == GDK_KEY_s || event->keyval == GDK_KEY_S))
{
try
{
@@ -1788,14 +1704,14 @@ static gboolean icvOnKeyPress(GtkWidget* widget, GdkEventKey* event, gpointer us
switch( event->keyval )
{
case GDK_Escape:
case GDK_KEY_Escape:
code = 27;
break;
case GDK_Return:
case GDK_Linefeed:
case GDK_KEY_Return:
case GDK_KEY_Linefeed:
code = 13;
break;
case GDK_Tab:
case GDK_KEY_Tab:
code = '\t';
break;
default:
@@ -1959,13 +1875,8 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da
image_widget->scaled_image )
{
// image origin is not necessarily at (0,0)
#if defined (GTK_VERSION3)
int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2;
int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2;
#else
int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2;
int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2;
#endif //GTK_VERSION3
pt.x = cvFloor( ((pt32f.x-x0)*image_widget->original_image->cols)/
image_widget->scaled_image->cols );
pt.y = cvFloor( ((pt32f.y-y0)*image_widget->original_image->rows)/
+1 -16
View File
@@ -2024,7 +2024,7 @@ static void icvUpdateTrackbar(CvTrackbar& trackbar, int pos)
memcpy(pos_text, trackbar.name.c_str(), name_len + 1);
}
sprintf(pos_text + strlen(pos_text), "%s: %d\n", suffix, pos);
snprintf(pos_text + strlen(pos_text), sizeof(pos_text) - strlen(pos_text), "%s: %d\n", suffix, pos);
SetWindowText(trackbar.buddy, pos_text);
}
}
@@ -2412,21 +2412,6 @@ std::shared_ptr<CvTrackbar> createTrackbar_(CvWindow& window, const std::string&
/* Retrieve current buttons count */
int bcount = (int)SendMessage(window.toolbar.toolbar, TB_BUTTONCOUNT, 0, 0);
if (bcount > 0)
{
/* If this is not the first button then we need to
separate it from the previous one */
tbs.iBitmap = 0;
tbs.idCommand = bcount; // Set button id to it's number
tbs.iString = 0;
tbs.fsStyle = TBSTYLE_SEP;
tbs.fsState = TBSTATE_ENABLED;
SendMessage(window.toolbar.toolbar, TB_ADDBUTTONS, 1, (LPARAM)&tbs);
// Retrieve current buttons count
bcount = (int)SendMessage(window.toolbar.toolbar, TB_BUTTONCOUNT, 0, 0);
}
/* Add a button which we're going to cover with the slider */
tbs.iBitmap = 0;
tbs.idCommand = bcount; // Set button id to it's number