知乎周源微信
I have a 42" HDTV in Seattle that's hooked up all the time as an "Embodied Social Proxy." It's a portal between the Microsoft Redmond campus and my house here in Oregon. I've blogged about Embodied Social Proxies before as well as shot video of one for Channel 9. It's called the "HanselCart" around work, although recently it's stopped being a cart and now it's a whole office that folks in Building 42 can drop by and see me, er, the Virtual Me.
我有一个42"在西雅图HDTV多数民众赞成迷上了所有的时间作为‘体现社会代理。’这是微软Redmond园区和我的家在这里在俄勒冈州之间的门户网站。我的博客上讲述体现社会代理前以及拍摄第9频道的视频,它被称为“ HanselCart”,尽管最近它不再是购物车,而现在却是整个办公室,42号楼的人们可以前来看看我,或者是Virtual Me。
One of the things that hasn't been 100% smooth is that while the LifeCam Cinema HD 720p is a nice camera, I can't MOVE it. I have to ask folks to move it for me, which is a slight irritant.
并非100%平滑的事情之一是,虽然LifeCam Cinema HD 720p是一款不错的相机,但我无法移动它。 我必须要求人们为我移动它,这有点刺激。
I'm getting ready to head up to Seattle for a meeting. While I was packing I found this TrackerPod motorized WebCam pan/tilt/zoom in my junk closet. I must have purchased it a long time ago and forgotten. I drilled a hole into the metal base of the LifeCam Cinema HD and superglued it while half-threading it on the TrackerPod's standard tripod-style male screw.
我准备去西雅图开会。 在打包时,我在垃圾柜中发现了这个TrackerPod电动WebCam平移/倾斜/缩放。 我一定很久以前就已经买了它,却忘记了。 我在LifeCam Cinema HD的金属底座上钻了一个Kong,然后在TrackerPod的标准三脚架式外螺纹上半拧了一下,然后将其粘合。
It's late, but I figured it I was going up to Seattle tomorrow, maybe I could hack something together quickly with this device and take it with me. There's a Custom Programming API page on the TrackerPod site with a TrackerPod COM Client.
已经很晚了,但是我想明天我要去西雅图,也许我可以用这个设备快速破解一些东西,然后随身携带。 在TrackerPod站点上有一个带有TrackerPod COM客户端的“自定义编程API”页面。
This is what I built in action:
这是我构建的动作:
Here's how I did it in 40 minutes. First, I made a new ASP.NET MVC 3 web project, keeping the default template. This is quick and dirty, right?
这是我在40分钟内完成的操作。 首先,我创建了一个新的ASP.NET MVC 3 Web项目,保留了默认模板。 这又快又脏,对吗?
Yes, I used a <TABLE>, sue me.
是的,我使用了<TABLE>来起诉我。
Here's the complete Razor View. I knew that I'd want a bunch of buttons to move the camera, and I assumed I would use jQuery to make an AJAX to the server side running ASP.NET MVC. I'm using the latest jQuery 1.4.4 and I'm getting it from the updated Microsoft cookieless CDN (Content Delivery Network.)
这是完整的“剃刀视图”。 我知道我想要一堆按钮来移动相机,并且我假设我会使用jQuery在运行ASP.NET MVC的服务器端制作AJAX。 我正在使用最新的jQuery 1.4.4,并且从更新的Microsoft无cookie CDN(内容交付网络)中获取它。
Rather than making a complex switch statement for the different buttons or different event handlers, I decided to use arbitrary HTML5 data attributes. Each INPUT Button has attributes like data-xvalue and data-yvalue.
我决定使用任意HTML5数据属性,而不是为不同的按钮或不同的事件处理程序创建复杂的switch语句。 每个“输入”按钮都有诸如data-xvalue和data-yvalue之类的属性。
There's one Click() handler hooked up to all Buttons. It gets the values of those data attributes, then POSTs the data to the Move method of the Home Controller.
有一个Click()处理函数连接到所有Button。 它获取这些数据属性的值,然后将数据发布到本地控制器的Move方法。
@{
View.Title = "Home Page";
}
<script src="•http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"
type="text/javascript"></script>
<table border="0">
<tr>
<td></td><td>
<input type="button" value=" up " name="up"
data-xvalue="0" data-yvalue="-10" data-method="0" />
</td><td></td>
</tr>
<tr>
<td>
<input type="button" value="left" name="left"
data-xvalue="10" data-yvalue="0" data-method="0" />
</td>
<td>
<input type="button" value="home" name="home"
data-xvalue="0" data-yvalue="0" data-method="1" />
</td>
<td>
<input type="button" value="right" name="right"
data-xvalue="-10" data-yvalue="0"
data-method="0" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="button" value="down" name="down"
data-xvalue="0" data-yvalue="10" data-method="0" />
</td>
<td>
</td>
</tr>
</table>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function () {
$('input').click(function (event) {
var target = event.target;
x = $(target).data('xvalue');
y = $(target).data('yvalue');
m = $(target).data('method');
$.post("/Home/Move", { x: x, y: y, method: m });
}
);
});
//]]>
</script>
In the Home Controller, there's a method called Move(int x, int y, int method) where method is the way to move the camera - relative is 0 or absolute is 1. That's part of the camera's calling convention.
在Home Controller中,有一个名为Move(int x,int y,int method)的方法,其中method是移动摄像机的方式-相对值为0或绝对值为1。这是摄像机调用约定的一部分。
using TRACKERPOD_DUAL_COMLib;
namespace TrackerPodWeb.Controllers
{
public class HomeController : Controller
{
private dynamic cam = MvcApplication.myCameraInstance;
[HttpPost]
public void Move(int x, int y, int method)
{
cam.x = x;
cam.y = y;
cam.move_method = method;
cam.move();
}
public ActionResult Index()
{
return View();
}
}
}
See that dynamic object? That was the part that blew me away. I'm so used to COM Interop being a freaking nightmare from .NET that I spent most of the time messing with COM Interfaces and Type Libraries and exceptions when I realized that C# 4 was supposed to fix all that.
看到那个动态物体? 那是让我震惊的部分。 我很习惯COM Interop成为.NET的噩梦,当我意识到C#4应该解决所有这些问题时,我大部分时间都花在弄乱COM接口和类型库以及异常上。
Like I've been saying about Razor - "stop thinking about syntax and just use it." - the same applies to COM interop in .NET 4 (Remember that the Visual Basic guys have have this nice experience for years...that's why VB is such a popular business automation language.)
就像我一直在谈论Razor一样-“停止思考语法,而只是使用它。” -.NET 4中的COM互操作性也是如此(请记住,Visual Basic专家已经有多年的良好经验了,这就是为什么VB是这么流行的业务自动化语言的原因。)
Just use the dynamic keyword and start calling COM methods. Seriously, it just worked. I was copy/pasting code from the TrackerCam's VB6 (yes Visual Basic 6) samples into C#4 and other than a few semicolons, it was working directly!
只需使用dynamic关键字并开始调用COM方法。 认真地说,它只是有效。 我正在将TrackerCam的VB6(是Visual Basic 6)示例中的代码复制/粘贴到C#4中,除了几个分号以外,它可以直接工作!
Here's my Web Application's startup code:
这是我的Web应用程序的启动代码:
public static dynamic myCameraInstance { get; set; }
protected void Application_Start()
{
//snip the MVC init stuff...
myCameraInstance = new TrackerPod();
myCameraInstance.app_name = "hanselcam";
myCameraInstance.initialize();
}
Here I hang on to the COM object for the camera as a poor man's singleton for use elsewhere. I should probably put guard-code around this to make sure it doesn't disappear or something but it's working so far. It should be a proper singleton I think.
在这里,我以穷人的单身身份挂在摄像机的COM对象上,以供其他地方使用。 我可能应该在此周围加上保护代码,以确保它不会消失或出现某种情况,但是到目前为止已经可以使用了。 我认为应该是一个合适的单身人士。
Then I use that instance in my HomeController and call the COM methods in Move(). ASP.NET MVC takes care of the binding from jQuery to the Action Method, and .NET 4, C# and the DLR take care of the call into the COM TrackerCam stuff.
然后,在HomeController中使用该实例,并在Move()中调用COM方法。 ASP.NET MVC负责从jQuery到Action Method的绑定,而.NET 4,C#和DLR负责对COM TrackerCam的调用。
HTML5+jQuery -> ASP.NET MVC -> C# 4 dynamic keyword -> DLR COM Binder -> COM Library = It just works.
HTML5 + jQuery-> ASP.NET MVC-> C#4动态关键字-> DLR COM活页夹-> COM库=可以使用。
There's some HTML5 attributes, five lines of JS here and basically four lines of COM interop on my Move() method.
有一些HTML5属性,这里有5行JS,在我的Move()方法上基本上有4行COM互操作。
Now I'll be able to control my Seattle WebCam from Oregon. I may make it so I can control it from the
Office Communicator
Lync chat client or something. It'd also be nice if someone wrapped up the TrackerPod as a nice C# library and put it on CodePlex.
现在,我将能够从俄勒冈州控制我的Seattle WebCam。 我可能会这样做,以便可以从
Office Communicator
Lync聊天客户端等控制它。 如果有人将TrackerPod包装成一个不错的C#库并将其放在CodePlex上,那也很好。
I'll add that to my ToDo list, or perhaps you will, Dear Reader. ;)
亲爱的读者,我会将其添加到“待办事项”列表中。 ;)
Related Links
相关链接
VIDEO: Hanselminutes on 9: Embodied Social Proxies (and Remote Video Heads!) with Microsoft Research
YOUTUBE VIDEO: Embodied Social Proxy: Connecting Hub-and-Satellite Teams
YOUTUBE视频:经验丰富的社交代理:连接中心和卫星团队
Virtual Camaraderie - A Persistent Video "Portal" for the Remote Worker
Buy a TrackerCam
- Full Disclosure: I took a second just now and got an affiliate code for a TrackerCam because it was easy to use this camera. I bought the TrackerPod mount myself years and found it in my closet tonight. I don't know anyone at Eagletron. 全面披露:我刚刚花了一秒钟时间,并获得了TrackerCam的会员代码,因为它易于使用。 我自己购买了TrackerPod坐骑多年,并于今晚在衣橱中找到了它。 我在Eagletron不认识任何人。
Buy a TrackerCam
知乎周源微信
1588



被折叠的 条评论
为什么被折叠?



