Kinect For Windows V2 로 특정 좌표의 Z값(깊이)를 가져오는 코드입니다.


이 코드를 통해 x, y 값으로 z 값을 가져오실수 있습니다.


X, Y 좌표는 ColorFrame 의 해상도인 1920x1080 기준입니다.


Z 값은 Float 으로 리턴되며 키넥트 센서로부터의 미터 거리를 뜻합니다.


먼저 이 코드를 사용하시려면 Kienct for Windows V2 센서와 Kinect SDK 2.0, Visual Studio 2013 이 필요합니다.


이 코드는 WPF 프로그램의 소스 일부이며 사용하실때 자신의 코드에 맞게 수정하시어 사용하시기 바랍니다.


MapColorFrameToCameraSpace() 함수가 아래처럼 매번 프레임이 들어올때마다 실행될 경우 프로그램이 많이 느려지는 영향이 있으므로 주의하시기 바랍니다.



더 자세한 설명은 이 링크에서 영문으로 확인하실수 있습니다.

https://gist.github.com/taylor224/1a534cb9287a4205c91f




public partial class MainWindow : Window
{
private KinectSensor kinectSensor = null;
private CoordinateMapper coordinateMapper = null;
private MultiSourceFrameReader multiFrameSourceReader = null;
public MainWindow()
{
InitializeComponent();
// one sensor is currently supported
this.kinectSensor = KinectSensor.GetDefault();
// get the coordinate mapper
this.coordinateMapper = this.kinectSensor.CoordinateMapper;
// get the depth (display) extents
FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
FrameDescription frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription;
// open multiframereader for depth, color, and bodyindex frames
this.multiFrameSourceReader = this.kinectSensor.OpenMultiSourceFrameReader(FrameSourceTypes.Depth | FrameSourceTypes.Color | FrameSourceTypes.Body);
this.multiFrameSourceReader.MultiSourceFrameArrived += this.Reader_MultiSourceFrameArrived;
}
private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
{
MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame();
if (multiSourceFrame != null)
{
using (DepthFrame depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame())
{
if (depthFrame != null)
{
// Specified X, Y coordinate
// In 1920 x 1080 color frame
double x = 1000;
double y = 900;
FrameDescription depthFrameDescription = depthFrame.FrameDescription;
depthWidth = depthFrameDescription.Width;
depthHeight = depthFrameDescription.Height;
depthframeData = new ushort[depthWidth * depthHeight];
depthFrame.CopyFrameDataToArray(depthframeData);
CameraSpacePoint[] csp = new CameraSpacePoint[1920 * 1080];
this.coordinateMapper.MapColorFrameToCameraSpace(depthframeData, csp);
// Depth(Z Position) of specified coordinate
float DepthPosition = csp[(1920 * Convert.ToInt16(y)) + Convert.ToInt16(x)].Z;
}
}
}
}
}






윈도우 8에서 터치 이벤트를 만들기 위해 Touch Injection API 를 사용하던 도중 발생한 문제에 대한 해결 방법입니다.


Touch Injection 은 Windows 8 부터 지원되는 Windows API 이며 User32.dll 에서 Import 하실수 있습니다.


원래는 C++ 만 지원하는 API 이나 C# 에서도 지원이 가능하게 끔 만들어진 라이브러리가 있습니다.


https://code.msdn.microsoft.com/TouchInjection-on-Windows-885150d2#content


이 라이브러리를 사용하면 C# 에서도 터치 이벤트를 만들어낼수 있습니다.



아래는 제가 이 라이브러리를 사용하면서 발생했던 문제에 대한 해결 방법입니다.





문제사항해결방법
InitializeTouchInjection() 에 Parameter를 넣으면 터치이벤트가 아예 동작하지 않음InitializeTouchInjection() 에서 Parameter를 모두 제거해서 해결
양손 적용시 터치가 한군데에서만 연속적으로 클릭되던 문제각 손이 각각 업데이트 되지만 업데이트는 2개 모두 하던 방식에서 각 손만 임시 contact를 만들어 각각 업데이트 하도록 해서 Injection 시키도록 하여 해결
터치인젝션으로 터치클릭 & 무브가 안되는 문제터치클릭을 위해서 UPDATE / INRANGE / INCONTACT 옵션을 사용했는데 문제는 이 이벤트를 발생시키기 전에 DOWN / INRANGE / INCONTACT 이벤트를 발생시켜야 이 이벤트가 정상적으로 동작하여서 터치가 UP된 후 다시 터치클릭 & 무브 하려할때 해당 이벤트가 발생되지 않았으면 발생시키도록 수정
터치가 한쪽밖에 안됨기존에 터치가 한군데에서만 연속적으로 클릭되던 문제의 원인이 LeftHand 신호를 받지 않았기 때문에 발생했던 문제였기 때문에 임시로 해결했던 contacttemp 를 만들어 각각 업데이트 하도록 Injection 시키던걸 양손 모두 한꺼번에 업데이트 하도록 변경하여서 수정
두 손 터치가 제대로 되지 않는 문제스택오버플로우에 따르면 TOUCH_FEEDBACK_DEFAULT 는 윈도우의 Pen and Touch 설정에 영향을 받기 때문에 여러가지 문제가 생길수도 있어서 TOUCH_FEEDBACK_INDIRECT 를 통해 InitializeTouchInjection()을 초기화해서 해결 http://stackoverflow.com/questions/20875283/why-is-only-one-touch-being-injected-when-using-touch-injection-api-with-win8
두 손 터치가 인식은 되지만 터치클릭이 되지 않는 문제Touch Down and Move 하기 전 이전 포인트 플래그가 터치가 올라갔을때 이면 Touch Down 플래그를 등록하는데 등록한 후 한번 Move 를 진행하고 그 다음번에 Touch Down and Move 를 위한 플래그로 변경시키는 방식에서 애초에 이전 플래그가 터치가 올라갔을때 이면 Touch Down 플래그를 등록한 후 바로 TouchInjection()을 호출하여 처리한 후 Touch Down and Move 를 위한 플래그를 넣고 Move 하고 Injection 하도록 하여서 해결



파이썬으로 만든 우체국택배 택배 배송정보를 가져오는 코드입니다.


택배 송장번호를 입력하시면 배송정보를 가져옵니다.


아래 주소에서 더 예쁘게 보실수 있습니다.

https://gist.github.com/taylor224/704e46a627519d035eb9




# -*- coding: utf8 -*-

 
import urllib, httplib, BeautifulSoup
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
 
realurl = 'http://service.epost.go.kr/trace.RetrieveRegiPrclDeliv.postal?sid1='
posturl = 'trace.epost.go.kr'
 
 
def getpost(sid):
params = {
'target_command' : 'kpl.tts.tt.epost.cmd.RetrieveOrderConvEpostPoCMD',
'sid1' : sid,
'RE_ORDID' : 'null'
}
params = urllib.urlencode(params)
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conn = httplib.HTTPConnection(posturl)
conn.request("POST", "/xtts/servlet/kpl.tts.common.svl.SttSVL", params, headers)
response = conn.getresponse()
data = response.read()
conn.close()
 
try:
soup = BeautifulSoup.BeautifulSoup(data)
addressee = soup('table', {'class' : 'traceTable traceTableType02', 'summary' : '발송인/수취인 정보'})[0].tbody.findAll('tr')[1].td.string
statuslist = soup('table', {'class' : 'traceTable traceTableType02', 'summary' : '세부결과를 보여드립니다.'})[0].tbody.findAll('tr')
status = []
 
status.append({ 'type' : 'addressee',
'addressee' : addressee
})
 
for i in range(len(statuslist)):
if i == 1:
continue
else:
tdlist = statuslist[i].findAll('td')
if statuslist[i].get('id') == 'transport1' or statuslist[i].get('id') == 'transport2':
continue
# When Received
if len(tdlist) == 1:
statusreceiver = tdlist[0].string
status.append({ 'type' : 'recipient',
'recipient' : statusreceiver.strip()
})
else:
statusdate = tdlist[0].string
statustime = tdlist[1].string
statuslocation = tdlist[2].a.string
nowstatus = tdlist[3].string
statusdetail = tdlist[4].string
status.append({ 'type' : 'status',
'date' : statusdate,
'time' : statustime,
'location' : statuslocation,
'status' : nowstatus,
'detail' : statusdetail
})
 
for statusdata in status:
for key in statusdata.keys():
if statusdata[key]:
statusdata[key] = statusdata[key].strip()
 
return status
except IndexError:
return False
 
 
data = getpost('postnumber')
 
if not data:
print 'Invalid Number'
else:
for status in data:
if status['type'] is 'addressee':
print status['addressee']
if status['type'] is 'recipient':
print status['recipient']
if status['type'] is 'status':
print status['date']
print status['time']
print status['location']
print status['status']
print status['detail']