I'm trying to read some frames from the built-in camera of a Macbook pro using opencv 4.1.0 with c++. Below is the code I have:
#include "opencv2/opencv.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>
#include <unistd.h>
using namespace cv;
using namespace std;
int main(int, char**) {
VideoCapture cap(0);
if(!cap.isOpened())
cerr<<"Error! unable to open camera!";
return -1;
cout << "Start grabbing" << endl
<< "Press any key to terminate" << endl;
Mat frame;
namedWindow("Live");
for (;;)
{
// wait for a new frame from camera and store it into 'frame'
cap.read(frame);
// check if we succeeded
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
// show live and wait for a key with timeout long enough to show images
imshow("Live", frame);
if (waitKey(5) >= 0)
break;
}
return 0;
}
When calling
VideoCapture cap(0);
the error I'm getting is:
testApp[11889:464240] +[AVCaptureDevice authorizationStatusForMediaType:]: unrecognized selector sent to class 0x7fff9f79cd50
[ERROR:0] VIDEOIO(AVFOUNDATION): raised unknown C++ exception!
I tried replacing 0 with other indices, but none of them work. Anyone know what is going on?
What version of macOS are you running on? I had the exact same issue but in Java. I solved it today by upgrading my OS from High Sierra to Mojave version 10.14 and updating the Xcode command line tools in the terminal using xcode-select --install.
I think the reason we got this problem is that Xcode command line tools - which provides the api (AVFoundation) to access camera on macOS and ios - was too old and therefore not compatible with the newly released OpenCV4.1.0. So my suggestion would be try to update your Xcode command line tools. In my case, I needed to upgrade my OS in order to get a newer version of it.
I had the same issue but in python. I wanted to access the webcam and capture images, but continued to get this error. What solved my problem was a simple SMC reset of the macbook.
Related
I made a new command-line tool C++ project in Xcode, with the following main.cpp:
#include <iostream>
int main() {
std::cout << "Hello, World!\n";
}
When I try to profile it in Instruments with any template, I get the following error before my program even starts:
Failed to execute loader thread for /Applications/Xcode.app/Contents/SharedFrameworks/DVTInstrumentsFoundation.framework/Resources/liboainject.dylib in target; target process <pid> likely exited
I get the same error when I try running Instruments with xctrace.
How do I get Instruments to properly load my programs?
Setup:
Xcode version: 13.4.1 (13F100)
Hardware: 2020 M1 MacBook Air
I want to write SystemC code using the Xcode IDE. I have set it all up and the code I use for testing my Installation builds just fine, but it runs always into Thread 1: EXC_BAD_ACCESS exception, no matter what I do.
I tried to comment everything out, until only the systemc header include and the sc_main was left. When I tried normal c++ code in a different project, to see if it was a general Xcode problem, it work fine and ran into no exception.
I use this generic Hello World-code to test my Installation:
#include <systemc>
//Hello_world is module name
SC_MODULE (hello_world) {
SC_CTOR (hello_world) {
// Nothing in constructor
}
void say_hello() {
//Print "Hello World" to the console.
std::cout << "Hello World.\n";
}
};
// sc_main in top level function like in C++ main
int sc_main(int argc, char* argv[]) {
hello_world hello("HELLO");
//Print the hello world
hello.say_hello();
return(0);
}
After the code ran for a few seconds, it always crashes with: Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeef3ffff8).
EDIT:
My Config:
- SystemC: v2.3.3
- Xcode: v10.2.1 (10E1001)
- Compiler: (I ran gcc --version)
- LLV: v10.0.1 (clang-1001.0.46.4)
- c++: v4.2.1
Im using std=gnu++98 (Compiler Default) as c++language Dialect, everything else ran into build errors.
EXC_BAD_ACCESS happens when system can not return from an execution block, such as infinite loop or recursion.
you should take a look at stack trace in the Debugger navigator and see which function is getting called and never returns OR which function(s) are calling over and over.
Don't forget to run project in DEBUG mode. (NOT release)
If you're using SystemC 2.3.2, you might be running into the following issue (on macOS 10.13 or later): http://forums.accellera.org/topic/6079-make-check-return-fail/. This issue is assumed to be fixed in SystemC 2.3.3.
You can avoid it by compiling SystemC 2.3.2 with ../configure --disable-async-updates ... or by moving to SystemC 2.3.3 and enabling C++11 (might be the default on a recent Xcode version, you can check the value of the SC_CPLUSPLUS macro in your model).
I did it! I built SystemC with Cmake following the steps provided in this answer: Setting up a SystemC project with CMake: undefined reference to sc_core
. In the CMakeLists.txt I set CMAKE_CXX_STANDARD explicitly to 11 and built the project via the command line and cmake.
Thanks for the help:)
I wrote a simple console application, and tried to debug it. But when I start debugging, in application output appears this message: Run in Terminal is not supported with the LLDB backend..
I use Qt Creator 4.1.0 on Mac OS X 10.11.
Here is an example of code that I tried to debug:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int a;
cin >> a;
cout << "a^2 = " << a * a;
return 0;
}
I also met this problem.
If I create a new C/C++ (Non-Qt project), the debugger doesn't work. However, if I create a Qt console project, the debugger works well.
There is the gdb debbugger wich is the GNU debbugger.
Here there is a tutorial
I am trying to use Qt Creator 3.5.1 to debug a piece of software I wrote. I noticed that whilst debugging my program would just halt at random points and I mistook these issues for threading problems. However, eventually I found out that even when I ran the simplest of programs the debugger would keep running for all eternity without finishing.
I am running on a Mac (El Capitan), with Qt 5.5.1 and Xcode 7.3.
This is my very simple test program:
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Howdy, this is a simple test program." << std::endl;
return 0;
}
When I run this in debugging mode in Qt Creator without setting any breakpoints it just never finishes:
Debugging starts
Howdy, this is a simple test program.
It is only when I press the stop button several times that the debugger comes back at me with Debugging has finished
When I look at the "Debugger log view" it shows me a Python exception of something crashing. I have no idea how to troubleshoot this though.
ERROR: Lldb stderr: Exception in thread Thread-1:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/Stan/Qt5.5.1/Qt Creator.app/Contents/Resources/debugger/lldbbridge.py", line 765, in loop
self.handleEvent(event)
File "/Users/Stan/Qt5.5.1/Qt Creator.app/Contents/Resources/debugger/lldbbridge.py", line 1383, in handleEvent
% self.hexencode(msg))
File "/Users/Stan/Qt5.5.1/Qt Creator.app/Contents/Resources/debugger/dumper.py", line 478, in hex encode
return s.encode("hex") eAttributeError: 'NoneType' object has no attribute 'encode'
It might be nothing, but I have quite a challenge on my hands right now and I'd rather not work with a debugger I can't trust.
Thanks.
Apparently, you can fix the problem directly by applying this patch in your Qt Creator's sources: https://codereview.qt-project.org/#/c/154748/
It worked for me.
After downloading the latest toolkit and compiling/running the code that I currently have, I get a debug assertion error with any sort of file IO functions. Even the code below will exit with an assertion error when fprintf is called.
//main.cu
#include <stdio.h>
#include <stdlib.h>
int main ( void ) {
FILE* foo;
foo=fopen("C:\\asdfsa.txt","w");
fprintf(foo,"wtf\n");
fclose(foo);
return 0;
}
I am using CUDA toolkit 5.0, and Visual studio.
Any idea on what is going on? My code worked fine on my older computer with an old version cuda toolkit.
Check the fopen return value. Looks like you are running the code on the entirely new environmnent - maybe you can't create the file in the C:\ (e.g. this may require admin permissions)