小编dau*_*tor的帖子

如何将CVImageBufferRef转换为UIImage

我试图从相机捕获视频.我已经得到了captureOutput:didOutputSampleBuffer:回调触发器,它给了我一个样本缓冲区,然后我转换为CVImageBufferRef.我然后尝试将该图像转换为UIImage我可以在我的应用程序中查看的图像.

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
    /*Lock the image buffer*/
    CVPixelBufferLockBaseAddress(imageBuffer,0); 
    /*Get information about the image*/
    uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); 
    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 
    size_t width = CVPixelBufferGetWidth(imageBuffer); 
    size_t height = CVPixelBufferGetHeight(imageBuffer); 

    /*We unlock the  image buffer*/
    CVPixelBufferUnlockBaseAddress(imageBuffer,0);

    /*Create a CGImageRef from the CVImageBufferRef*/
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); 
    CGImageRef newImage = CGBitmapContextCreateImage(newContext); 

    /*We release some …
Run Code Online (Sandbox Code Playgroud)

iphone uiimage

23
推荐指数
3
解决办法
3万
查看次数

奇怪的循环问题

我不确定这是不是一个bug,所以我想也许你们大家可能想看一看.

问题出在这个代码上:

for i=0,1,.05 do
    print(i)
end
Run Code Online (Sandbox Code Playgroud)

输出应该是:

0
.05
.1
--snip--
.95
1
Run Code Online (Sandbox Code Playgroud)

相反,输出是:

0
.05
.1
--snip--
.95
Run Code Online (Sandbox Code Playgroud)

while循环也发生了同样的问题:

w = 0
while w <= 1 do
    print(w)
    w = w + .05
end
--output:
0
.05
.1
--snip--
.95
Run Code Online (Sandbox Code Playgroud)

w的值为1,可以在循环后通过print语句验证.

我已尽可能验证任何小于或等于.05的步骤都会产生此错误.任何高于.05的步骤应该没问题.我确认1/19(0.052631579)确实打印了1.(显然,像19.9或10.5这样的小数分母不会产生[0,1]包含的输出.)是否有可能这不是语言的错误?解释器和常规Lua文件都会产生此错误.

floating-point lua

7
推荐指数
1
解决办法
720
查看次数

从L API推送lua函数作为表成员

使用lua_register(L,lua_func_name,c_func)将C函数作为函数成员或使用lua函数注册C函数没有问题;

但是如何告诉lua我想从C 传递luaFoo()作为"foober"的函数回调参数?lua_pushcfunction - 推送C函数,lua_pushstring只推送一个普通的字符串,所以回调字段变成了一个字符串,而不是一个函数.

Lua代码:

CALLBACKS = {};
FOO = 0;

function luaFoo()
FOO = FOO + 1;
end;

function addCallback(_name, _callback)
CALLBACKS[_name] = _callback;
end;

function doCallback(_name)
CALLBACKS[_name]();
end;
Run Code Online (Sandbox Code Playgroud)

C代码:

static int c_foo(lua_State* l)
{
  printf("FOO\n");
  return 0;
}

/*load lua script*/;
lua_State* l = /*get lua state*/;
lua_getglobal(l, "addCallback");
lua_pushstring(l, "foober");
//What push for luaFoo()
lua_pushcfunction(l, c_foo);
lua_call(l, 2, 0);

lua_getglobal(l, "doCallback");
lua_pushstring(l, "foober");
lua_call(l, 1, 0);
Run Code Online (Sandbox Code Playgroud)

熟悉 - 如果我得到已经注册了lua_register的 C函数,如何将它们作为回调参数从C传递.所以我们注册 …

c lua

5
推荐指数
1
解决办法
1318
查看次数

只有一个tcp服务器允许带有Lua的ESP8266

我正在研究ESP8266,我正在尝试用Lua编程.我尝试创建TCP服务器,但是当我在下面编写示例代码时,我将错误消息名称"只允许一个tcp服务器".我创建了一个服务器而且我无法关闭.

我该如何解决?

print("ESP8266 mode is: " .. wifi.getmode());

cfg = {};
-- Set the SSID of the module in AP mode and access password
cfg.ssid = "SSID";
cfg.pwd = "password";
if ssid and password then
    print("ESP8266 SSID is: " .. cfg.ssid .. " and PASSWORD is: " ..
            cfg.password)
end;
-- Now you should see an SSID wireless router named ESP_STATION when you scan for available WIFI networks
-- Lets connect to the module from a computer of mobile device. …
Run Code Online (Sandbox Code Playgroud)

lua tcpserver esp8266

2
推荐指数
1
解决办法
4402
查看次数

标签 统计

lua ×3

c ×1

esp8266 ×1

floating-point ×1

iphone ×1

tcpserver ×1

uiimage ×1