小编Car*_*ger的帖子

从CMSampleBufferRef创建的UIImage没有显示在UIImageView中?

我正试图从相机实时显示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)

为了解决容易出错的问题:

  • 使用UIImagePickerController不是一个选项(最终我们将实际使用图像做事)
  • 我知道正在调用处理程序(NSLog调用已经完成,我看到了输出)
  • 我知道我已正确设置了IBOutlet声明.如果我使用上面的注释代码从Web加载任意图像而不是简单地发送setImage:theImage到imageView,则图像被正确加载(并且第二次调用NSLog报告非零对象).
  • 至少在基本范围内,我得到的图像imageFromSampleBuffer:很好,因为NSLog报告的大小为360x480,这是我预期的大小.

我正在使用的代码是最近发布的AVFoundation苹果公司提供片段在这里.

特别是,这是我用来设置AVCaptureSession对象和朋友的代码(我很少理解),并从Core Video缓冲区创建UIImage对象(这就是imageFromSampleBuffer方法).

最后,我可以让应用程序崩溃,如果我尝试发送drawInRect:到一个普通的UIView子类与UIImage …

iphone avfoundation uiimageview uiimage ios4

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

在dijkstra_shortest_paths中使用捆绑属性作为权重映射

也许这是一个愚蠢的问题,但我正在尝试使用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的文档对我来说是非常不透明的.如果您可以告诉我描述示例的文档中的哪个位置,我也会非常高兴.

先感谢您!

c++ boost-graph

9
推荐指数
3
解决办法
3527
查看次数

标签 统计

avfoundation ×1

boost-graph ×1

c++ ×1

ios4 ×1

iphone ×1

uiimage ×1

uiimageview ×1