这是我的代码:
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django import http
from django.http import HttpResponse
def main(request, template_name='index.html'):
HttpResponse.set_cookie('logged_in_status', 'zjm1126')
context ={
'a':a,
'cookie':HttpResponse.get_cookie('logged_in_status'),
}
return render_to_response(template_name, context)
#return http.HttpResponsePermanentRedirect(template_name)
Run Code Online (Sandbox Code Playgroud)
它引发了这个例外:
unbound method set_cookie() must be called with HttpResponse instance as first argument (got str instance instead)
Run Code Online (Sandbox Code Playgroud)
我能做什么?
基本上,我想有以下语义:
#include <functional>
#include <iostream>
class test
{
public:
void add(std::function<void()> f)
{
f();
}
void operator()()
{
++x;
}
int x = 33;
};
int main()
{
test t;
t.add(t);
// wanted: x == 34 instead: x == 33 since add(t) copies it
}
Run Code Online (Sandbox Code Playgroud)
我理解std :: function包装了一个可调用对象的副本,但有没有办法使用std :: function获取对可调用对象的引用?
我注意到,当在JPEG格式的设备上读取相同的照片时,像素值不匹配.它们很接近但不同.转换为PNG文件时,像素值似乎匹配.
这似乎是由于跨设备的(非)压缩算法.无论如何,这就是我想到的.有没有办法读取JPEG文件,以便跨设备从照片中检索相同的像素?我没有在BitmapFactory Options组件中看到一个选项.
当处理跨设备的图像的像素值时,当前应用以下内容来维持大小:
Options options = new Options();
options.inScaled = false;
options.inPreferQualityOverSpeed = true;
Run Code Online (Sandbox Code Playgroud)
目前比较像素与以下只是为了看几个(近似匹配,但不相等):
int[] pixels = new int[bitmapF.getWidth() * bitmapF.getHeight()];
bitmapF.getPixels(pixels, 0, bitmapF.getWidth(), 0, 0, bitmapF.getWidth(), bitmapF.getHeight());
Log.d("pixel entries", "pixels = " + pixels[233] + " - " + pixels[4002] + " - " + pixels[11391]);
Run Code Online (Sandbox Code Playgroud)
注意:如果读取未压缩的同一文件的PNG版本,则值与预期的相同.
例如,三星Galaxy S4和三星Galaxy S5甚至具有与assets文件夹中存储的相同jpeg(运行相同测试活动)不同的像素.
像素[233]例如在s5上是-5205635但在s4上是-5336451.像素[4002]也稍微偏离.但是像素[11391]在这个jpeg图片上的两个设备上是相等的.
我使用glMapBufferRange()Android上的OpenGL-ES 3.0 使用的代码如下所示:
glBindBuffer(GL_ARRAY_BUFFER, myVertexBufferName);
glBufferData(GL_ARRAY_BUFFER, myVertexBufferSize, null, GL_STATIC_DRAW);
ByteBuffer mappedBuffer = (ByteBuffer)glMapBufferRange(
GL_ARRAY_BUFFER,
0, myVertexBufferSize,
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
// [fill buffer...]
glUnmapBuffer(GL_ARRAY_BUFFER);
Run Code Online (Sandbox Code Playgroud)
我的问题是关于向下转换的结果glMapBufferRange(),以ByteBuffer在第三行.glMapBufferRange()被声明为返回一个Buffer:
public static Buffer glMapBufferRange (int target, int offset, int length, int access)
在我的测试平台上,该函数返回一个子类,ByteBuffer因此转换工作正常,但对支持OpenGL-ES 3+的所有平台或Android版本进行此假设似乎不太安全.虽然看起来很合理,但我没有找到任何保证它的文档,如果保证它似乎应该声明函数返回ByteBuffer.
使用Buffer返回的正确方法(最好是文档支持)是glMapBufferRange()什么?
我正在尝试进行必要的三方授权,以便在浏览器中调用Twitter API.该过程从通过POST签名请求获取请求令牌开始/oauth/request_token(这也是Twitter开始的登录方式).
我的问题是,在浏览器POST到Twitter API端点之前,它想要使用OPTIONS方法预检请求.此预检请求始终返回状态400(错误请求).
下面是一个示例,您可以将其剪切并粘贴到支持Fetch API的浏览器控制台中:
fetch('https://api.twitter.com/oauth/request_token', { method: 'POST', mode: 'cors', headers: new Headers({ authorization: 'xxx' }), body: 'oauth_callback=http%3A%2F%2Flocalhost%2F' });
Run Code Online (Sandbox Code Playgroud)
在Chrome上,预检请求如下所示(Firefox类似):
OPTIONS /oauth/request_token HTTP/1.1
accept:*/*
accept-encoding:gzip, deflate, sdch
accept-language:en-US,en;q=0.8
access-control-request-headers:authorization, content-type
access-control-request-method:POST
cache-control:no-cache
origin:null
pragma:no-cache
user-agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36
Run Code Online (Sandbox Code Playgroud)
预检反应如下:
HTTP/1.1 400 Bad Request
content-length: 0
date: Tue, 08 Mar 2016 22:21:37 GMT
server: tsa_a
x-connection-hash: 529e3d8338caeb980077637d86db5df1
Run Code Online (Sandbox Code Playgroud)
请注意,问题不在于我没有在上面的示例中指定真正的授权标头.授权标头的值未在预检请求中使用. …
我看到onPoseAvailable()回调和回调的姿势之间存在显着差异Tango.getPoseAtTime().我写了一个测试程序,在那里onPoseAvailable()我记录了传递的姿势并用于getPoseAtTime()使用之前2个回调的时间戳来请求姿势.KEY_BOOLEAN_SMOOTH_POSE已配置false.这是执行该操作的代码(timestamps_成员变量是a LinkedList<Double>):
@Override
public void onPoseAvailable(TangoPoseData poseData) {
if (poseData != null && poseData.statusCode == TangoPoseData.POSE_VALID) {
Log.v("bug",
String.format("onPoseAvailable t: %f, base: %d, target %d, p: (%f, %f, %f)",
poseData.timestamp,
poseData.baseFrame,
poseData.targetFrame,
poseData.translation[0], poseData.translation[1], poseData.translation[2]));
timestamps_.add(poseData.timestamp);
if (timestamps_.size() > 3)
timestamps_.remove();
}
if (timestamps_.isEmpty())
return;
TangoCoordinateFramePair framePair = new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE);
poseData = tango_.getPoseAtTime(timestamps_.getFirst(), framePair);
if (poseData != null && poseData.statusCode == TangoPoseData.POSE_VALID) { …Run Code Online (Sandbox Code Playgroud) 我正在使用Closure编译器来创建Chrome扩展,我想让源映射用于调试.通过将浏览器直接指向源代码树中的页面,并将特殊的sourceMappingURL添加到已编译的javascript文件的末尾(所有内容都在一个目录中),我可以使源映射正常工作:
debugger;document.getElementById("hello").innerHTML="Hello, world!";
//@ sourceMappingURL=background-compiled.map
Run Code Online (Sandbox Code Playgroud)
但是当我访问与扩展相同的脚本时,我只能看到已编译的javascript而不是原始源.我确实将Chrome调试器配置为在两种情况下启用源映射,否则它们都执行相同而没有错误.源地图是不是在扩展中工作,还是在设置时我缺少什么?
我尝试过Chrome 25 stable和Chrome 27 canary,两者都有相同的行为.
google-chrome google-chrome-extension google-chrome-devtools
我试图了解源DOM中的哪些事件通过<content>元素在shadow DOM中接收时的样子.我正在阅读Shadow DOM W3C草案,我并不完全理解它,但听起来事件要从EventListener附件的角度"重新定位".
在事件路径跨越多个节点树的情况下,调整事件关于事件目标的信息以维持封装.事件重定向是计算调度事件的节点的每个祖先的相对目标的过程.相对目标是在保持封装的同时最准确地表示给定祖先的调度事件的目标的节点.
和
在事件发送时:
- Event target和currentTarget属性必须返回调用事件侦听器的节点的相对目标
所以这里是一个简单的Polymer自定义元素,只是将其子元素放入容器中,并向容器添加一个ClickListener(在shadow DOM中).在这种情况下,孩子是一个按钮.
<!DOCTYPE html>
<html>
<head>
<script src="bower_components/platform/platform.js"></script>
<link rel="import" href="bower_components/polymer/polymer.html">
</head>
<body unresolved>
<polymer-element name="foo-bar">
<template>
<div id="internal-container" style="background-color:red; width:100%;">
<content></content>
</div>
</template>
<script>
Polymer("foo-bar", {
clickHandler: function(event) {
console.log(event);
var element = event.target;
while (element) {
console.log(element.tagName, element.id);
element = element.parentElement;
}
},
ready: function() {
this.shadowRoot.querySelector('#internal-container').addEventListener('click', this.clickHandler);
}
});
</script>
</polymer-element>
<foo-bar id="custom-element">
<button>Click me</button>
</foo-bar>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我在Chrome 38.0.2075.0金丝雀上运行时,当我点击按钮时,我得到:
MouseEvent {dataTransfer: null, toElement: …Run Code Online (Sandbox Code Playgroud) 该项目探戈C API文档说,TANGO_CALIBRATION_POLYNOMIAL_3_PARAMETERS镜头失真建模为:
x_corr_px = x_px(1 + k1*r2 + k2*r4 + k3*r6)y_corr_px = y_px(1 + k1*r2 + k2*r4 + k3*r6)
也就是说,无失真的坐标是一个幂级数功能扭曲的坐标.Java API中还有另一个定义,但该描述不够详细,无法确定函数映射的方向.
我在使事情正确注册方面遇到了很多麻烦,我怀疑映射实际上可能是相反的方向,即失真的坐标是未失真坐标的幂级数.如果摄像机校准是使用OpenCV生成的,那么问题的原因可能是OpenCV文档与自身相矛盾.最容易找到和理解的描述是OpenCV摄像机校准教程,它与Project Tango文档一致:
但另一方面,OpenCV API文档指定映射采用另一种方式:
我在OpenCV上的实验表明它的API文档看起来是正确的并且教程是错误的.正k1(所有其他失真参数设置为零)表示枕形失真,负k1表示桶形失真.这与维基百科关于布朗康拉迪模型的说法相符,并且与Tsai模型相反.请注意,失真可以通过任何方式建模,具体取决于使数学更方便的原因.我针对这种不匹配打开了一个针对OpenCV 的错误.
所以我的问题是:Project Tango镜头失真模型是否与OpenCV中实现的相同(尽管文档)?
这是我从彩色相机拍摄的图像(可以看到轻微的枕形):

以下是Tango服务报告的相机校准:
distortion = {double[5]@3402}
[0] = 0.23019999265670776
[1] = -0.6723999977111816
[2] = 0.6520439982414246
[3] = 0.0
[4] = 0.0
calibrationType …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过利用来即时压缩使用Boost Log库创建的日志文件boost::iostreams::gzip_compressor.因此,当我打电话时BOOST_LOG(),输出会即时压缩.这是我到目前为止所尝试的:
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/sources/logger.hpp>
void init()
{
// Construct the sink
typedef boost::log::sinks::synchronous_sink< boost::log::sinks::text_ostream_backend > text_sink;
boost::shared_ptr< text_sink > sink = boost::make_shared< text_sink >();
boost::shared_ptr< std::ofstream > file = boost::make_shared< std::ofstream >(
"sample.gz", std::ios_base::out | std::ios_base::binary );
boost::iostreams::filtering_ostream out;
out.push( boost::iostreams::gzip_compressor() );
out.push( *(file.get()) );
for( int i = 0; i < …Run Code Online (Sandbox Code Playgroud)