VideoCapture.isOpened() is always returning false
I'm new to openCV and I'm having trouble with VideoCapture.isOpened() always returning false. I've seen other posts that have similar problems, but I'm not managing to make headway towards a solution for my case.
Text version of what is in the screenshot:
#import <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#import "OpenCVWrapper.h"
using namespace cv;
using namespace std;
@implementation OpenCVWrapper
+ (int) testing : (string) filePath { // couldn't input parameter as NSString* because that made the VideoCapture's constructor not work, this way it recognized constructor pattern
VideoCapture cap(filePath);
cout << "did it work : " << cap.isOpened() << endl;
Mat frame;
cap >> frame; // get the next frame from video
frame.push_back(frame);
cout << "mat = " << endl << frame << endl;
return 1;
}
+ (NSString *)openCVVersionString {
return [NSString stringWithFormat:@"OpenCV Version %s", CV_VERSION];
}
@end
And below is how they are called (in Swift):
// first function's call
let videoFileURL = Bundle.main.url(forResource: "spaceMinimal", withExtension: "mp4")
var test = OpenCVWrapper.testing(videoFileURL.path)
// second function's call
print("Before : \(OpenCVWrapper.openCVVersionString())")
The image shows the two functions in my header that uses openCV libraries. I call both functions on my first ViewController, and you can see the output at the bottom of the image. I've pasted the output below as well:
did it work : 0 // This is the result for
VideoCapture.isOpened()
Before : OpenCV Version 4.1.0 // This is the result of the other function, which is working
For whatever reason, VideoCapture is not opening the mp4 file, even though the mp4 file is in the directory (as can be seen in the image).
From other posts it seems like there may be an issue with some ffmpeg dll or something (I'm not familiar with these), but I have no idea where to go from here. Please help!
additional details: - openCV-4.0 - 1.0 included the ios package framework - using XCode 10.1 - my openCVWrapper.h :
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface OpenCVWrapper : UICollectionView
+ (NSString *)openCVVersionString;
+ (int) testing : (NSString*)filePath; // had to pass in NSString* here instead of string because 'string' isn't recognised in this file
@end
NS_ASSUME_NONNULL_END
please replace the useless screenshot with a TEXT version of your code / errors, thank you.
Sure @berak, I've added the code in text above, both what is in the screenshot and also how it is called in my View Controller. As for errors, there are no errors that show up. The issue I'm facing is with VideoCapture not seemingly doing what I believe it should be
thanks a ton, much better now, it can be indexed for search, ppl can paste / try your code, etc.
thanks for the tip @berak!