59 #include "rnr/rnrconfig.h" 62 #include "rnr/CameraCv.h" 63 #include "rnr/CameraGst.h" 65 #include "gtest/gtest.h" 67 #include "opencv/cv.h" 68 #include "opencv/highgui.h" 71 #include <gdk/gdkkeysyms.h> 74 using namespace ::
std;
75 using namespace ::
rnr;
78 #define KEY_L_SHIFT 0xe1 79 #define KEY_R_SHIFT 0xe2
80 #define KEY_L_CTRL 0xe3
81 #define KEY_R_CTRL 0xe4
82 #define KEY_L_ALT 0xe9
83 #define KEY_R_ALT 0xea
96 " 'q' quit with success\n" 99 " 'c' click snapshot\n" 100 " '+/-' increase/decrease video resolution\n" 101 " '>/<' increase/decrease image resolution\n";
110 static CamRes
incRes(
const CamRes &resCur)
114 switch( resCur.width )
149 static CamRes
decRes(
const CamRes &resCur)
153 switch( resCur.width )
193 string strVideoWinName(
"ut-CameraCv - Video");
194 string strImageWinName(
"ut-CameraCv - Image");
204 LOG_SET_THRESHOLD(LOG_LEVEL_DIAG3);
215 namedWindow(strVideoWinName);
239 if( cam.startVideo(resVideo) < 0 )
247 if( cam.stopVideo() < 0 )
255 if( cam.clickImage(snapshot, resImage) == OK )
257 namedWindow(strImageWinName);
258 imshow(strImageWinName, snapshot);
263 resVideo =
incRes(resVideo);
264 printf(
"%dx%d video resolution.\n", resVideo.width, resVideo.height);
265 if( cam.isCameraRunning() )
267 cam.startVideo(resVideo);
272 resVideo =
decRes(resVideo);
273 printf(
"%dx%d video resolution.\n", resVideo.width, resVideo.height);
274 if( cam.isCameraRunning() )
276 cam.startVideo(resVideo);
281 resImage =
incRes(resImage);
282 printf(
"%dx%d image resolution.\n", resImage.width, resImage.height);
286 resImage =
decRes(resImage);
287 printf(
"%dx%d image resolution.\n", resImage.width, resImage.height);
291 if( cam.isCameraRunning() && !cam.isTakingAnImage() )
293 if( cam.grabFrame(frame) == OK )
295 imshow(strVideoWinName, frame);
309 printf(
"0x%02x huh?\n", c);
314 destroyWindow(strVideoWinName);
315 destroyWindow(strImageWinName);
317 LOG_SET_THRESHOLD(LOG_LEVEL_OFF);
327 static gulong GstWinXid = 0;
328 static uint_t GtkLastKey = 0;
341 #if GTK_CHECK_VERSION(2,18,0) 348 if( !gdk_window_ensure_native(w->window) )
350 LOGERROR(
"Couldn't create native window needed for GstXOverlay!");
354 #ifdef GDK_WINDOWING_X11 355 GstWinXid = GDK_WINDOW_XID(gtk_widget_get_window(w));
370 *(
int *)user_data = 1;
391 timer = g_timeout_add(delay,
GtkAlarm, &expired);
394 while( gtk_main_iteration_do(FALSE) &&
398 if( delay > 0 && !expired )
400 g_source_remove(timer);
427 switch( event->keyval )
440 code =
event->keyval;
443 GtkLastKey = (code & 0xffff) | (event->state << 16);
456 static const char *TestMenuAddOn =
" 't' text overlay\n";
458 string strVideoWinName(
"ut-CameraGst - Video");
459 string strImageWinName(
"ut-CameraGst - Image");
472 bool bEnterText =
false;
479 LOG_SET_THRESHOLD(LOG_LEVEL_DIAG3);
489 printf(
"%s", TestMenuAddOn);
496 wMain = gtk_window_new(GTK_WINDOW_TOPLEVEL);
497 wWin = GTK_WINDOW(wMain);
502 gtk_window_set_title(wWin, strVideoWinName.c_str());
503 gtk_window_resize(wWin, 640, 480);
504 gtk_window_set_decorated(wWin, TRUE);
509 wGst = gtk_drawing_area_new();
510 g_object_set(G_OBJECT(wGst),
511 "width-request", 640,
512 "height-request", 480,
514 nIdRealize = g_signal_connect(wGst,
"realize",
516 gtk_widget_set_double_buffered(wGst, FALSE);
517 gtk_container_add(GTK_CONTAINER(wMain), wGst);
522 nIdKeyPress = gtk_signal_connect(GTK_OBJECT(wMain),
"key-press-event",
525 gtk_widget_show_all(wMain);
527 cam.setXid(GstWinXid);
550 cam.setTextOverlay(bufText);
554 cam.clearTextOverlay();
574 printf(
"%s", TestMenuAddOn);
583 if( cam.startVideo(resVideo) < 0 )
591 if( cam.stopVideo() < 0 )
599 if( cam.clickImage(snapshot, resImage) == OK )
601 namedWindow(strImageWinName);
602 imshow(strImageWinName, snapshot);
607 resVideo =
incRes(resVideo);
608 printf(
"%dx%d video resolution.\n", resVideo.width, resVideo.height);
609 if( cam.isCameraRunning() )
611 cam.startVideo(resVideo);
616 resVideo =
decRes(resVideo);
617 printf(
"%dx%d video resolution.\n", resVideo.width, resVideo.height);
618 if( cam.isCameraRunning() )
620 cam.startVideo(resVideo);
625 resImage =
incRes(resImage);
626 printf(
"%dx%d image resolution.\n", resImage.width, resImage.height);
630 resImage =
decRes(resImage);
631 printf(
"%dx%d image resolution.\n", resImage.width, resImage.height);
653 printf(
"0x%02x huh?\n", c);
661 gtk_signal_disconnect(GTK_OBJECT(wMain), nIdKeyPress);
662 gtk_widget_destroy(wMain);
663 destroyWindow(strImageWinName);
665 gtk_main_iteration_do(FALSE);
667 while( gtk_events_pending() )
669 gtk_main_iteration_do(FALSE);
672 LOG_SET_THRESHOLD(LOG_LEVEL_OFF);
const CamRes CamRes1440x1080
1440 x 1080 resolution
const CamRes CamRes2592x1944
2592 x 1944 resolution
const CamRes CamRes1600x1200
1600 x 1200 resolution
gboolean GtkOnKeyPress(GtkWidget *w, GdkEventKey *event, gpointer *user_data)
Keyboard press event handler.
#define KEY_L_SHIFT
left shift key code
gboolean GtkAlarm(gpointer user_data)
Timeout expiry callback.
const CamRes CamRes1024x768
1024 x 768 resolution
const CamRes CamResQVGA
Quarter VGA 320 x 240 res.
#define KEY_L_CTRL
left ctrl key code
void GtkOnRealizeGstWin(GtkWidget *w, gpointer user_data)
Realize GStreamer video window callback.
static CamRes incRes(const CamRes &resCur)
Increment resolution to the next comman resolution.
int GtkWaitKey(int delay)
Wait for keypress or timeout.
static const char * TestMenu
Test menu.
static int testCameraCv()
Test OpenCv CameraCv class.
#define KEY_R_SHIFT
right shift key code
static CamRes decRes(const CamRes &resCur)
Decrement resolution to the previous comman resolution.
TEST(Camera, CameraCv)
Test OpenCv camera class.
const CamRes CamRes2048x1536
2048 x 1536 resolution
#define KEY_R_CTRL
right ctrl key code
#define KEY_L_ALT
left alt key code
#define KEY_R_ALT
right alt key code
const CamRes CamResVGA
VGA 640 x 480 resolution.
static int testCameraGst()
Test GStreamer CameraGst class.