我正试图从相机实时显示UIImage,看来我的UIImageView没有正确显示图像.这是AVCaptureVideoDataOutputSampleBufferDelegate必须实现的方法
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
// Create a UIImage from the sample buffer data
UIImage *theImage = [self imageFromSampleBuffer:sampleBuffer];
// NSLog(@"Got an image! %f %f", theImage.size.width, theImage.size.height);
// NSLog(@"The image view is %@", imageView);
// UIImage *theImage = [[UIImage alloc] initWithData:[NSData
// dataWithContentsOfURL:[NSURL
// URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
[self.session stopRunning];
[imageView setImage: theImage];
}
Run Code Online (Sandbox Code Playgroud)
为了解决容易出错的问题:
setImage:theImage到imageView,则图像被正确加载(并且第二次调用NSLog报告非零对象).imageFromSampleBuffer:很好,因为NSLog报告的大小为360x480,这是我预期的大小.我正在使用的代码是最近发布的AVFoundation苹果公司提供片段在这里.
特别是,这是我用来设置AVCaptureSession对象和朋友的代码(我很少理解),并从Core Video缓冲区创建UIImage对象(这就是imageFromSampleBuffer方法).
最后,我可以让应用程序崩溃,如果我尝试发送drawInRect:到一个普通的UIView子类与UIImage …
也许这是一个愚蠢的问题,但我正在尝试使用BGL dijkstra_shortest_paths,特别是使用我的Edge捆绑属性的字段作为权重图.我的尝试目前导致了数十页的编译器错误,所以我希望有人知道如何帮助我.这基本上就是我的代码:
struct GraphEdge {
float length;
// other cruft
};
struct GraphVertex {
...
};
typedef boost::adjacency_list
<boost::vecS, boost::vecS, boost::directedS,
GraphVertex, GraphEdge> GraphType;
Run Code Online (Sandbox Code Playgroud)
我可以毫无问题地填充图表,但是当涉及到呼叫时dijkstra_shortest_paths,我遇到了麻烦.我想用这个length领域.具体来说,我想知道在这样的通话中需要什么样的增强伏都教才能适应:
GraphType m_graph;
vector<int> predecessor(num_vertices(m_graph));
vector<float> distances(num_vertices(m_graph), 0.0f);
vector<int> vertex_index_map(num_vertices(m_graph));
for (size_t i=0; i<vertex_index_map.size(); ++i) {
vertex_index_map[i] = i;
}
dijkstra_shortest_paths(m_graph, vertex_from, predecessor, distances,
weightmap, vertex_index_map,
std::less<float>(), closed_plus<float>(),
(std::numeric_limits<float>::max)(), 0.0f,
default_dijkstra_visitor());
// How do I write the right version of weightmap here?
Run Code Online (Sandbox Code Playgroud)
这样,weightmap会以某种方式将我的图形的特定边缘与length属性中的相应字段相关联.我确信有一种简单的方法可以做到这一点,但BGL的文档对我来说是非常不透明的.如果您可以告诉我描述示例的文档中的哪个位置,我也会非常高兴.
先感谢您!