OpenCVForUnity
OpenCVForUnity copied to clipboard
VideoCapture.Open Is not opening videos
Hi, i am trying to play a video of my own to get some work done but somehow i could not get it to play I am using HOGDescriptorSample.cs to play video But nothing works its just black screen
This is the code Of Start Mehtod
` void Start () { rgbMat = new Mat ();
capture = new VideoCapture ();
// capture.open (Utils.getFilePath ("768x576_mjpeg.mjpeg"));
capture.open(Utils.getFilePath("GOPR0082 (240P).avi"));
Debug.Log(" path utilss " + Utils.getFilePath("GOPR0082 (240P).avi"));
if (capture.isOpened ()) {
Debug.Log ("capture.isOpened() true");
} else {
Debug.Log ("capture.isOpened() false");
}
Debug.Log ("CAP_PROP_FORMAT: " + capture.get (Videoio.CAP_PROP_FORMAT));
Debug.Log ("CV_CAP_PROP_PREVIEW_FORMAT: " + capture.get (Videoio.CV_CAP_PROP_PREVIEW_FORMAT));
//My Addition
//Debug.Log("CV_CAP_PROP_PREVIEW_FORMAT: " + capture.get(Videoio));
Debug.Log ("CAP_PROP_POS_MSEC: " + capture.get (Videoio.CAP_PROP_POS_MSEC));
Debug.Log ("CAP_PROP_POS_FRAMES: " + capture.get (Videoio.CAP_PROP_POS_FRAMES));
Debug.Log ("CAP_PROP_POS_AVI_RATIO: " + capture.get (Videoio.CAP_PROP_POS_AVI_RATIO));
Debug.Log ("CAP_PROP_FRAME_COUNT: " + capture.get (Videoio.CAP_PROP_FRAME_COUNT));
Debug.Log ("CAP_PROP_FPS: " + capture.get (Videoio.CAP_PROP_FPS));
Debug.Log ("CAP_PROP_FRAME_WIDTH: " + capture.get (Videoio.CAP_PROP_FRAME_WIDTH));
Debug.Log ("CAP_PROP_FRAME_HEIGHT: " + capture.get (Videoio.CAP_PROP_FRAME_HEIGHT));
capture.grab ();
capture.retrieve (rgbMat, 0);
int frameWidth = rgbMat.cols ();
int frameHeight = rgbMat.rows ();
colors = new Color32[frameWidth * frameHeight];
texture = new Texture2D (frameWidth, frameHeight, TextureFormat.RGBA32, false);
gameObject.transform.localScale = new Vector3 ((float)frameWidth, (float)frameHeight, 1);
float widthScale = (float)Screen.width / (float)frameWidth;
float heightScale = (float)Screen.height / (float)frameHeight;
if (widthScale < heightScale) {
Camera.main.orthographicSize = ((float)frameWidth * (float)Screen.height / (float)Screen.width) / 2;
Debug.Log("Camera main orthographicSize " + Camera.main.orthographicSize );
} else {
Camera.main.orthographicSize = (float)frameHeight / 2;
}
capture.set (Videoio.CAP_PROP_POS_FRAMES, 0);
gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
des = new HOGDescriptor();
}`
Thank you for your inquiry.
VideoCapture class of OpenCVforUnity supports Motion JPEG Video(MJPEG) codec on all platforms. .avi and .mov files are supported by mac and win(require opencv_ffmpeg310.dll https://forum.unity.com/threads/released-opencv-for-unity.277080/page-16#post-2723212).
Also, By combining Unity's VideoPlayer class and OpenCVforUnity, it is possible to read video files of other codecs. https://github.com/EnoxSoftware/VideoPlayerWithOpenCVForUnityExample
Regerds, EnoxSoftware
It seems that you can't do HOGDescriptorSample.cs kind of work with this VideoPlayerWithOpenCVForUnityExample.cs file.
@EnoxSoftware Hi , I have downloaded the opencv version 3.1.0 and extracted it in C: drive and then copied and placed (opencv_ffmpeg310.dll) in the root directory of my project and then i tried (.avi , .ogv , .mp4) but no avail it still not Opening the (VideoCapture.Open) so can you now elaborate what is going wrong here or have i done anything wrong (the example video is working fun but none other videos are working)
Also, i have also downloaded the package of the (video player + videoWriter ) and it is playing the desired video but how will i do the object recognition in this video, as its is not (video Capture) Class so i can not use any https://docs.opencv.org/3.1.0/d8/dfe/classcv_1_1VideoCapture.html#ab5b7391cd5ec50e7237e575a758f6f05 or if i can then how as its is not doing (videocapture.grab())
I’m sorry I made a mistake. Please use version 3.3.0.
If you use the “VideoCapture(string filename) or VideoWriter class”, require setup. 1)Download "OpenCV for Windows Version 3.3.0"(http://opencv.org/downloads.html). 2)Set PATH variable to "opencv_ffmpeg330.dll" or "opencv_ffmpeg330_64.dll". if 32bit, "¥path¥to¥opencv¥build¥x86¥vc14¥bin¥". if 64bit, "¥path¥to¥opencv¥build¥x64¥vc14¥bin¥". Or 2)Copy to Project Folder.
In my environment these files worked correctly with VideoCaptureExample. http://www.gomplayer.jp/img/sample/mp4_h264_aac.mp4 http://www.gomplayer.jp/img/sample/mp4_mpeg4_aac.mp4 http://www.gomplayer.jp/img/sample/mov_h264_aac.mov
I have tried both aforementioned techniques for "opencv_ffmpeg330_64.dll" but my videos which is a avi and mp4 is not opening in ( videoCapture.Open() ) it is same as before black screen and videocapture is not open i am using HOGDescriptorSample.cs for this test
And please take a look at this situation below and give your advice Thanks... i have also downloaded the package of the (video player + videoWriter ) and it is playing the desired video but how will i do the object recognition in this video, as its is not (video Capture) Class so i can not use any https://docs.opencv.org/3.1.0/d8/dfe/classcv_1_1VideoCapture.html#ab5b7391cd5ec50e7237e575a758f6f05 or if i can then how as its is not doing (videocapture.grab())
@AR9Rizvi What version of OpenCVForUnity are you using?
Also, VideoPlayerWithOpenCVForUnityExample
https://github.com/EnoxSoftware/OpenCVForUnity/blob/master/Assets/OpenCVForUnity/Examples/MainModules/objdetect/HOGDescriptorExample/HOGDescriptorExample.cs#L124-L136 https://github.com/EnoxSoftware/VideoPlayerWithOpenCVForUnityExample/blob/master/Assets/VideoPlayerWithOpenCVForUnityExample/VideoPlayerWithOpenCVForUnityExample.cs#L72
// Update is called once per frame
void Update ()
{
if (videoPlayer.isPlaying && videoPlayer.texture != null) {
Utils.textureToTexture2D (videoPlayer.texture, videoTexture);
Utils.fastTexture2DToMat (videoTexture, rgbaMat);
//Please add the image processing you want to do here.
//////////////////////////////////////////////////////////////////
using (MatOfRect locations = new MatOfRect ())
using (MatOfDouble weights = new MatOfDouble ()) {
des.setSVMDetector (HOGDescriptor.getDefaultPeopleDetector ());
des.detectMultiScale (rgbaMat, locations, weights);
OpenCVForUnity.Rect[] rects = locations.toArray ();
for (int i = 0; i < rects.Length; i++) {
Imgproc.rectangle (rgbaMat, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (255, 0, 0,255), 2);
}
}
/////////////////////////////////////////////////////////////////
Utils.fastMatToTexture2D (rgbaMat, texture);
}
}