In this blog post I am just going to give overview about one of the application using 3D gesture. In fact the idea I am going to discuss came in mind when discussing about this new technology with my friends. And here is I am able to control Google earth using hand gestures in air. Just see video below to get idea, how does it work exactly
At first I downloaded SDK and Aurea GUI on which I could test functionality of HillStar development Kit. You can find these resources herehttp://www.microchip.com/pagehandler/en-us/technology/gestic/gettingstarted.html.
I tested Aurea GUI application which worked out of box with Hillstar development kit. Then I also tested SDK example codes which worked without problem.
For the current application I used one of the sample code from the given SDK which gives data on command line. In this project I had to control Google earth, but there is not way to in C to control google earth, hence I needed to send this data from the MGC3130 Application to Python application that controls Google earth using Google earth API for python. I used socket programming in this and transmitted data over local network using TCP. I could also use shared memory in this. And finally I have a working model that controls google earth.
Code snippets -
Here, I am just going to give details about add on codes which I did to make this application, rather than providing complete code.
Following is the TCP Client implemented in C (You can find lot of examples online about TCP client implementation in C)
- /*
- Create a TCP socket
- */
- #include<stdio.h>
- #include<winsock2.h>
- #include "console.h"
- #pragma comment(lib,"ws2_32.lib") //Winsock Library
- WSADATA wsa;
- SOCKET s;
- struct sockaddr_in server;
- char *message;
- int tcpInit(void)
- {
- printf("\nInitialising Winsock...");
- if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
- {
- printf("Failed. Error Code : %d",WSAGetLastError());
- return 1;
- }
- printf("Initialised.\n");
- //Create a socket
- if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
- {
- printf("Could not create socket : %d" , WSAGetLastError());
- }
- printf("Socket created.\n");
- server.sin_addr.s_addr = inet_addr("127.0.0.1");
- server.sin_family = AF_INET;
- server.sin_port = htons(5005 );
- //Connect to remote server
- if (connect(s , (struct sockaddr *)&server , sizeof(server)) < 0)
- {
- puts("connect error");
- return 1;
- }
- return 0;
- }
- int tcpSendData(char *uData)
- {
- //while (1)
- //{
- //puts("Connected");
- retry:
- //Send some data
- //message = "GET / HTTP/1.1\r\n\r\n";
- if( send(s , uData , strlen(uData) , 0) < 0)
- {
- puts("Send failed");
- return 1;
- goto retry;
- }
- Sleep(1);
- puts("Data Send\n");
- //}
- return 0;
- }
- // closesocket(s);
- // WSACleanup();
- // return 0;
- //}
- if(data->gestic_gesture != NULL) {
- /* Remember last gesture and reset it after 1s = 200 updates */
- if(data->gestic_gesture->gesture > 0 && data->gestic_gesture->gesture <= 6)
- data->last_gesture = data->gestic_gesture->gesture;
- else if(data->gestic_gesture->last_event > 1) //Shrenik
- data->last_gesture = 0;
- printf("Gesture: %s \n", gestures[data->last_gesture]);
- if(strcmp(gestures[data->last_gesture],"DNULL"))
- {
- tcpSendData(gestures[data->last_gesture]);
- }
- }
Before writing program you need to install Google python API package which is attached with this blog. Install this package as you install normally python package "setup.py install". Following is the python code snippet I am giving which does following job
1. Initiates TCP server over localhost with port numbe 5005.
2. Initiate Google earth APIs default variable value.
3. Reads Gesture data which comes over TCP port 5005 on localhost.
4. Parse that data in order to take specific action to google earth movement according to gesture.
5. Keep doing step 3 and 4 continuously.
- import socket
- import win32com.client, time
- googleEarth = win32com.client.Dispatch("GoogleEarth.ApplicationGE")
- while not googleEarth.IsInitialized():
- time.sleep(0.5)
- print "waiting for Google Earth to initialize"
- latitude=41.487942 # Latitude in degrees. Between -90 and 90.
- longitude=0#-81.6865 # Longitude in degrees. Between -180 and 180. to rotate the earth
- altitude=1000
- # in meters
- tilt=0 # looking to the horizon=90, looking to the center of Earth=0
- azimuth=370 # looking North=0, East=90, South=180, West=270
- speed=0.5
- # speed transition. must be >= 0, above 5.0 the transition is instantaneous
- range=0 # If not=0 camera will move backward from "range meters along the camera axis
- altMode=1 #Altitude mode that defines altitude reference origin (1=above ground, 2=absolute)
- focusDistance=10000000 #Zoom Value can be changed
- TCP_IP = '127.0.0.1'
- TCP_PORT = 5005
- BUFFER_SIZE = 20 # Normally 1024, but we want fast response
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.bind((TCP_IP, TCP_PORT))
- s.listen(1)
- conn, addr = s.accept()
- print 'Connection address:', addr
- while 1:
- data = conn.recv(BUFFER_SIZE)
- if not data: break
- #print "received data:", data
- #focusDistance=0
- #data=0
- if data == "DRIGHT":
- print "Right Direction longitude = ", longitude
- if longitude <= 180:
- longitude = longitude-10
- if longitude == -180:
- longitude = 180
- elif data == "DLEFT":
- if longitude >= -180:
- longitude = longitude+10
- if longitude == 180:
- longitude = -180
- print "Left Direction longitude = ", longitude
- elif data == "DUP":
- if tilt > 10:
- tilt = tilt - 10
- if tilt == 0:
- tilt = 90
- print "Up Direction tilt = ", tilt
- elif data == "DDOWN":
- if tilt < 90:
- tilt = tilt + 10
- if tilt == 90:
- tilt = 0
- print "Down Direction tilt = ", tilt
- elif data[0] == 'Z':
- print "Z data Direction"
- data = data[1:6]
- focusDistance = (int(data))
- print 'focus_distance z = ', focusDistance
- #conn.send(data)
- #conn.close()
- googleEarth.SetCameraParams (latitude, longitude, altitude, altMode, focusDistance, tilt, azimuth, speed)
- cam=googleEarth.GetCamera(True) # returns a ICameraInfoGE object
I hope you enjoyed this project. Let me know if any querry/ comments.
Regards,
Shrenik.
Comments
Post a Comment