- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Guys,
I am creating a program in Java for my Bachelor Thesis,
Scenario: Its an Image viewer controller by Gestures (Swipe right and left for next and prev.)
The images are saved in an array m.
Problem: When i use swipe gesture once, it repeates the action 2-4 times, so it skips some images or sometimes it doesnt work then i works suddently.
Its the same situation when i add println("swiping left"), then i shows "swiping left" repeated in the console.
What should i change to make the Program work more stable?? GestureStateType is still null the whole time!
here is my code
public class GestureViewer extends JFrame{ static ImageIcon m[]; static int i; static JLabel l; static JToggleButton like; static JToggleButton dislike; public GestureViewer(){ setLayout(new BorderLayout( )); setSize(1000,700); setVisible(true); JPanel p=new JPanel(new FlowLayout()); add(p,BorderLayout.SOUTH); like = new JToggleButton("like"); dislike = new JToggleButton("dislike"); p.add(like); p.add(dislike); add(p,BorderLayout.SOUTH); //images array m = new ImageIcon[4]; //images source in gallery m[0] = new ImageIcon("C:/Users/PC/Desktop/images/img1.png"); m[1] = new ImageIcon("C:/Users/PC/Desktop/images/img2.jpg"); m[2] = new ImageIcon("C:/Users/PC/Desktop/images/img3.jpg"); m[3] = new ImageIcon("C:/Users/PC/Desktop/images/img4.jpg"); l = new JLabel(); l.setBounds(400, 0, getWidth(), getHeight()); add(l,BorderLayout.CENTER); l.setIcon(m[0]); } public static <myImage> void main(String s[]) { GestureViewer xx= new GestureViewer(); System.out.println("Starting hand tracker."); // create the sense manager and enable the streams, // get the hand module, and initialize the pipeline PXCMSenseManager senseManager =PXCMSenseManager.CreateInstance(); senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR,640,480,60); senseManager.EnableHand(null); PXCMHandModule handModule = senseManager.QueryHand(); senseManager.Init(); // configure the hand module, we want all gestures // we also want a PXCHandData instance which we'll // later query for gesture data. We also enable // alerts if a hand is detected or lost PXCMHandData handData = handModule.CreateOutput(); PXCMHandData.GestureData gestureData = new PXCMHandData.GestureData(); PXCMHandConfiguration handConfig = handModule.CreateActiveConfiguration(); PXCMSession session= PXCMSession.CreateInstance(); PXCMPowerState ps=session.CreatePowerManager(); ps.SetState(PXCMPowerState.State.PERFORMANCE); handConfig.DisableAllGestures(); handConfig.EnableGesture("thumb_up"); handConfig.EnableGesture("thumb_down"); handConfig.EnableGesture("swipe_right"); handConfig.EnableGesture("swipe_left"); handConfig.EnableAllAlerts(); handConfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_DETECTED); handConfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED); handConfig.ApplyChanges(); PXCMCaptureManager captureMgr = senseManager.QueryCaptureManager(); captureMgr.FilterByDeviceInfo("RealSense",null, 0); pxcmStatus sts = senseManager.EnableHand(null); sts = senseManager.Init(); handConfig.Update(); if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) >= 0) { senseManager.Init(); //initialize if no error //int numOfHands = handData.QueryNumberOfHands(); //GestureStateType state = GestureStateType.GESTURE_STATE_START; for (int nframes = 0; nframes < 3000; nframes++) { sts = senseManager.AcquireFrame(true); if (sts.compareTo(pxcmStatus.PXCM_STATUS_NO_ERROR) < 0) break; while (senseManager.AcquireFrame(true).isSuccessful()) { // Retrieve current hand tracking results handData = handModule.CreateOutput(); handData.Update(); PXCMHandData.IHand hand = new PXCMHandData.IHand(); sts = handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME,0,hand); //getting the 3 gestures if (handData.IsGestureFired("thumb_up", gestureData)) { System.out.printf("thumb up!!\n"); like.setSelected(true); dislike.setSelected(false); } if (handData.IsGestureFired("swipe_left", gestureData)){ System.out.println("swipe left!!"); if(i==0) { JOptionPane.showMessageDialog(null,"This is first Image"); } else{ i=i-1; l.setIcon(m); } } if (handData.IsGestureFired("swipe_right", gestureData)){ System.out.println("swipe right!!"); if(i==m.length-1) { JOptionPane.showMessageDialog(null,"This is Last Image"); } else { i=i+1; l.setIcon(m); } } if (handData.IsGestureFired("thumb_down", gestureData)&&(gestureData.timeStamp > 200 * 365 *24 *60*60)){ System.out.println("thumb down!!"); dislike.setSelected(true); like.setSelected(false); } senseManager.ReleaseFrame(); } } handData.close(); senseManager.close(); handConfig.close(); } } }
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could try using a thread for image acquisition, and another for processing.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page