iOS 中的 OpenCV 无法正确解码帧
我正在尝试在 iOS 上使用 OpenCV 对视频帧进行一些像素分析。我已经尝试了几个 .MOV 文件(都是 MPEG-4 AVC),但它们似乎都无法正确解码。
问题: - 所有 cvGetCaptureProperty 调用都返回值 1 - cvGrabFrame(capture) 总是返回 true (它似乎没有找到最后一帧)
实际工作的东西 - 框架高度和宽度正确确定
有什么想法吗?我有来自 http://aptogo.co.uk 的 OpenCV 2.3.2 /2011/09/opencv-framework-for-ios/
NSURL *file = [[NSBundle mainBundle] URLForResource:@"sky" withExtension:@"MOV"];
CvCapture* capture = cvCaptureFromFile([[file path] UTF8String]);
if (!capture)
{
NSLog(@"Error loading file");
return;
}
cvQueryFrame(capture);
int width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
int height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
NSLog(@"dimensions = %dx%d", width, height); // returns 1x1
double framesPerSecond = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
NSLog(@"framesPerSecond = %f", framesPerSecond); // returns 1
int frameCount = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
NSLog(@"frameCount = %d", frameCount); // returns 1
int frameCounter = 0;
while (cvGrabFrame(capture))
{
frameCounter++;
//NSLog(@"got a frame! %d", frameCounter);
if (frameCounter % 50 == 0)
{
IplImage* frame = cvRetrieveFrame(capture);
NSLog(@"frame width: %d", frame->width); // works correctly
NSLog(@"frame height: %d", frame->height); // works correctly
}
if (frameCounter > 1000)
break; // this is here because the loop never stops on its own
}
cvReleaseCapture(&capture);
I'm trying to use OpenCV on iOS to do some pixel analysis on video frames. I've tried several .MOV files (all MPEG-4 AVC) but none of them seem to decode properly.
Problems:
- All cvGetCaptureProperty calls return a value of 1
- cvGrabFrame(capture) always returns true (it doesn't seem to find the last frame)
Things that are actually working
- Frame height and width are correctly determined
Any ideas? I have OpenCV 2.3.2 from http://aptogo.co.uk/2011/09/opencv-framework-for-ios/
NSURL *file = [[NSBundle mainBundle] URLForResource:@"sky" withExtension:@"MOV"];
CvCapture* capture = cvCaptureFromFile([[file path] UTF8String]);
if (!capture)
{
NSLog(@"Error loading file");
return;
}
cvQueryFrame(capture);
int width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
int height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
NSLog(@"dimensions = %dx%d", width, height); // returns 1x1
double framesPerSecond = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
NSLog(@"framesPerSecond = %f", framesPerSecond); // returns 1
int frameCount = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
NSLog(@"frameCount = %d", frameCount); // returns 1
int frameCounter = 0;
while (cvGrabFrame(capture))
{
frameCounter++;
//NSLog(@"got a frame! %d", frameCounter);
if (frameCounter % 50 == 0)
{
IplImage* frame = cvRetrieveFrame(capture);
NSLog(@"frame width: %d", frame->width); // works correctly
NSLog(@"frame height: %d", frame->height); // works correctly
}
if (frameCounter > 1000)
break; // this is here because the loop never stops on its own
}
cvReleaseCapture(&capture);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论