I have installed the opencv on MacPro and am trying to write a program which allow me to activate the cam, it is only to test opencv it build successfully, however, the cam is not on and I receive this message
saved enable noise cancellation setting is the same as the default(=1) pentest[30782:364297] [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data
my code is:
#include <iostream>
#include<opencv2/opencv.hpp>
using namespace cv;
int main(int argc, const char * argv[]) {
// insert code here...
VideoCapture cap(0);
while(true){
Mat Webcam;
cap.read(Webcam);
imshow("webcam",Webcam);
}
return 0;
}
I recently posted another answer that addresses this situation:
Put the Info.plist file with the desired NSCameraUsageDescription, NSMicrophoneUsageDescription (or others) with the assembled file from XCode (See screenshots below). For the Release and Debug versions.
Related
I am trying to read a video frame by frame and process it and write it back to another video file.
Part of the process is to read the video and in another part write it back into another video. I noted that when I am doing this, I am getting some artifacts on the generated video.
The simplest code that I can show the problem is as follow:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <conio.h>
using namespace cv;
using namespace std;
int main()
{
std::string inputFile = "D:\\MyData\\sample2.mp4";
std::string outputFileName = "D:\\MyData\\sample2out.mp4";
VideoCapture inputVideo;
inputVideo.open(inputFile);
VideoWriter videoWritter;
videoWritter.open(outputFileName, inputVideo.get(CAP_PROP_FOURCC), inputVideo.get(CAP_PROP_FPS),Size(inputVideo.get(CAP_PROP_FRAME_WIDTH), inputVideo.get(CAP_PROP_FRAME_HEIGHT)));
while (true) // loop until all frames read. this
{
cv::Mat frame;
// Capture frame-by-frame
inputVideo >> frame;
// If the frame is empty, break immediately
if (frame.empty())
break;
videoWritter << frame;
}
inputVideo.release();
videoWritter.release();
}
when I run this code, the output video has some artifacts that can be seen in the following image:
I also noted that the size of the output file became a lot larger than the original one ( input file ~ 98 Mbyte and output is around 143 Mbyte).
How can I fix this artifact? why the output size is bigger than the input file when the compression and other parameters are set to be the same?
I am using OpenCV 4.6 and Visual studio 2022 on windows 10.
Edit 1
I run the application on two videos, both of which are downloaded from the internet, one from a site (I can not remember the name of the site but it offers free videos) and the other downloaded from Youtube using a youtube downloader website.
I can share the videos, but I do not know how to upload them to this site. How can I share it?
I can see the same issue in both videos.
If I extract images and save them into a jpeg, the images are correct. but when I encode them into a video I can see the issue.
Edit 2
Sample files are uploaded here: https://www.filemail.com/d/kobthfbkbjanwqm
I am writing a suite of hardware tests that will run in a windows PE environment. I need to test the webcam but so far I am stumped. I compiled a small webcam capture program using the opencv library, but it is unable to detect the webcam. I have tried loading additional drivers, but it hasn't worked. Unfortunately I have not found any help online since apparently no one else is crazy/stupid enough to attempt this. Is this idea fundamentally flawed in some way, or is there a way to do this? Any help is appreciated.
Here is the code I am using that compiles and runs on my windows 10 machine:
#include "opencv2/opencv.hpp"
#include <cstdio>
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap;
// open the default camera, use something different from 0 otherwise;
// Check VideoCapture documentation.
if(!cap.isOpened()) // check if we succeeded
{
printf("Unable to open webcam");
return -1;
}
for(;;)
{
Mat frame;
cap >> frame;
if( frame.empty() ) break; // end of video stream
imshow("this is you, smile! :)", frame);
if( waitKey(10) == 27 ) break; // stop capturing by pressing ESC
}
// the camera will be closed automatically upon exit
// cap.close();
return 0;
}
Edit: I realized that the drivers were not loading on startup so I loaded them manually with drvload.exe. Now the webcam shows as functional when I do a WQL query(ConfigManagerErrorCode = 0) but my opencv program will still not detect it.
You won't get your cam to work, without adding some DLLs to your PE environment.
PE is a minimalistic WIndows that misses lots of functions due to minimize memory and diskspace consumption. It is only designed to offline edit Windows images, not to do hardware testing. Ran into similar issues some months ago.
I'm not sure if linking to this project is allowed here, but they sure have helpful information for you on that: TheOven
I need to convert videostream data to cv::gpumat. Initially I tried copying to cv::Mat and then use upload to load it to gpumat. This process is very slow(20ms for a 640*480 frame).
I need a method to convert from openni videostream to gpumat directly. I tried the following code but it gives run time error
I am using opencv3.1, cuda-8.0, gtx titanx on ubuntu 16.04
#include "opencv2/opencv_modules.hpp"
#include <opencv2/core.hpp>
#include <opencv2/cudacodec.hpp>
#include <opencv2/highgui.hpp>
int main(int argc, const char* argv[])
{
const std::string fname = argv[1];
cv::cuda::GpuMat d_frame;
cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(fname);
for (;;)
{
if (!d_reader->nextFrame(d_frame))
break;
cv::Mat frame;
d_frame.download(frame);
cv::imshow("GPU", frame);
if (cv::waitKey(3) > 0)
break;
}
return 0;
}
OpenCV Error: The function/feature is not implemented (The called functionality is disabled for current build or platform) in throw_no_cuda, file /home/krr/softwares/opencv-3.1.0/modules/core/include/opencv2/core/private.cuda.hpp, line 101
terminate called after throwing an instance of 'cv::Exception'
what(): /home/krr/softwares/opencv-3.1.0/modules/core/include/opencv2/core/private.cuda.hpp:101: error: (-213) The called functionality is disabled for current build or platform in function throw_no_cuda
Take a look into the source code. The framework called "throw_no_cuda()" (lines are different, version?). Also the error seems to be a duplicate of this one on github.
alalek:
https://developer.nvidia.com/nvidia-video-codec-sdk:
Note: For Video Codec SDK 7.0 and later, NVCUVID has been renamed to NVDECODE API.
OpenCV has no support for new API and there are no plans to add this.
The latest CUDA version with NVCUVID is ~ CUDA 6.5.
Consider using ffmpeg with enabled CUDA features (via normal cv::VideoCapture - but it can't work with CUDA's cv ::GpuMat).
And further:
dapicard:
I found a way to define the codec used by the FFMpeg backend :
export OPENCV_FFMPEG_CAPTURE_OPTIONS="video_codec|h264_cuvid"
More generally, it is possible to define theses parameters, using the syntax parameter_name|value;parameter_name2|value2
That is, to use the hardware capabilities to decode videos (which you tried). Sidenote: ffmpeg also offers options to transcode videos directly on the gpu (i.e. without moving fromes away from gpu memory).
Frankly, using the proposed method will not result in the matrix being delivered to your gpu memory directly, but only solve the error. I don't think it is possible to grab the memory directly from ffmpeg directly, so you are stuck with moving it.
I am trying to learn OpenCV and i encounter these two code, the task of both code is same just to show the image but latter one doesn't work. I am using opencv 2.4.6 and visual studio 12
the second doesnt load the image but shows error saying no image found
#include "cv.h"
#include "highgui.h"
int main() // this code works
{
IplImage* newImg;
newImg = cvLoadImage("boxing.jpg", 1);
cvNamedWindow("Window", 1);
cvShowImage("Window", newImg);
cvWaitKey(0);
cvDestroyWindow("Window");
cvReleaseImage(&newImg);
return 0;
}
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
int main() // this code doesn't works
{
Mat image;
image = imread("boxing.jpg");
namedWindow("original");
imshow("original",image);
cvWaitKey(5000);
return 0;
}
Just add
using namespace cv;
after the include statements and before the main function.
Why?
All the OpenCV classes and functions are declared in the namespace cv. Or otherwise, you can also use the scope resolution operator like cv::Mat, cv::imshow etc to access the OpenCV functionality.
Do not mix C functions with C++. While using OpenCv above 2.0 version (C++) you should call:
cv::WaitKey(5000);
as functions and classes starting with "cv" in names are obsolete.
believe it or not, you've got a linker problem.
cvLoadImage() takes a char*, imread() a std::string. if you can't use the latter, it's due to some std/c++ lib wrongly linked.
please check extra carefully, if you're linking release libs against a debug build (or the other way round),
if you accidentally changed the c-runtime (mutithreaded-dll).
I am trying to display video feed from IP- Camera(D-Link DCS 932L). I Have gone through topics for the same and tried the code from different posts, but am unable to get the video feed from the camera.
Here's the code which i tried.
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace cv;
int main(int argc, char *argv[])
{
Mat frame;
namedWindow("video", 1);
String url = "http://admin:admin#172.32.20.55:80/image/jpeg.cgi";
VideoCapture cap(url);
/* VideoCapture cap(0);*/
while ( cap.isOpened() )
{
cap >> frame;
if(frame.empty()) break;
imshow("video", frame);
if(waitKey(30) >= 0) break;
}
return 0;
}
I tried many different kind of url's but i was unable to display any video feed. I thought it might be code problem so I even tried displaying the USB Webcam and it worked. So now i come to conclusion that the problem seems to be with URL which am passing. Heres the list of urls which I tried. I got this Url options from iSpy.Here are those URL's
(JPEG)http://admin:admin#172.32.20.55:80?IMAGE.JPG
(JPEG)http://admin:admin#172.32.20.55:80/image/jpeg.cgi
(MPEG)http://admin:admin172.32.20.55:80/video.cgi?resolution=VGA
(MPEG)http://admin:admin172.32.20.55:80/video/mjpg.cgi
(MPEG)http://admin:admin172.32.20.55:80/mjpeg.cgi? user=admin&password=admin&channel=0
(MPEG)http://admin:pnqadmin172.32.20.55:80/VIDEO.CGI
Please let me know what can be probable problem for displaying the video feed.
Is their something to do with the setting of the OpenCv or something else.Please note that am using VS2010 and C++ Need help of all the Expert out their.
Thanks in advance.
I solved my problem. The problem was with URL. I changed the URL and it worked smooth..!
The URL i used was as follows.
"http://USER:PWD#IPADDRESS:8088/mjpeg.cgi?user=USERNAME&password=PWD&channel=0&.mjpg";
I keep getting the same error:
warning: Error opening file <../../modules/highgui/src/cap_ffmpeg_impl.hpp:529>
I was trying to stream MJPG video from a Foscam IP camera. The URL opened just fine but I couldn't read any frames. May be there was some problem with the video codec.
Here's a hack written in Python that worked for me: https://stackoverflow.com/a/18411168/3183051
Perhaps my answer is too late. Check if opencv_ffmpegXXX.dll or opencv_ffmpegXXX_64.dll (if you are building 64bit executable) is in the same folder where your executable is. Replace XXX with the number of opencv version you use.