'select timeout' for opencv application while running on yocto linux environment - opencv

We are trying to port opencv application on an single board computer which runs on Yocto Linux and while doing that we have had many issues. Issues related to drivers, which are solved by changing the configuration file of the kernel and all.
We were able to solve all those issues and finally, we are hitting the 'select timeout' error during below highlight line in the snapshot code.
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core.hpp>
#include <opencv2/core/core.hpp>
using namespace std;
int main(int, char**) {
cv::VideoCapture camera(0);
if (!camera.isOpened()) {
return 1;
}
cv::Mat frame;
while (camera.isOpened()) {
***camera >> frame;***
}
return 0;
}
This code does work on my local machine, but not on the SBC. Are there any leads for this issue to solve? I would be happy to share more details if required.
P.S.
Camera is well detected and thus not throwing any error at !camera.isOpened() code.
It gives the error 'select timeout' error at camera >> frame line.

Related

C++ Onnx-GPU Cuda Dll throws access violation

I am programming the first time on C++ and i have a not solvable problem at the moment.
My trained network works fine using Onnx-CPU but i have trouble running it on the GPU.
Enviroment and Versions:
Windows 10, RTX 3090 Driver: 516.59
Visual Studio Code Community 2022
Microsoft.ML.OnnxRuntime.Gpu 1.12.0
Cuda 11.4
cuDnn 8.2.2.26
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <vector>
#include <string>
#include <onnxruntime_cxx_api.h>
int main() {
const string imageFile = "image";
auto onnxFile = L"path to onnx file";
//Testing CV
cv::Mat img = cv::imread(imageFile)
//-----------------------------------------------GPU SUPPORT------------------------------------------------
auto providers = Ort::GetAvailableProviders();
for (auto provider : providers) {
cout << provider << endl;
}
Ort::Session session(nullptr);
Ort::Env env(OrtLoggingLevel::ORT_LOGGING_LEVEL_WARNING, "test");
Ort::SessionOptions session_options;
session_options.SetIntraOpNumThreads(1);
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CUDA(session_options, 0));//Crash is here
//----------------------------------------------------------------------------------------------------------
// create session
session = Ort::Session(env, onnxFile, sessionOptions);
}
The error i get is:
Exception thrown at 0x00007FFD36393F68 (cufft64_10.dll) in
programm.exe: 0xC0000005: Access violation writing location
0x000000D3562B0000. The file is in C:\Program Files\NVIDIA GPU
Computing Toolkit\CUDA\v11.4\bin\cufft64_10.dll.
I hope you can help me figure out what i have done wrong in my installation/code snippet.

Embarcadero C++10.4.2 ignoring namespaces sometimes

I am an experienced C++ developer, but new to Embarcadero.
I found the following code compiles, and it should not. What settings can I use to make the compiler be conformant?
#include <fstream>
int main()
{
auto ifs = ifstream("hellp");
}

ROS Image subscriber - window popup does not appear

I am following image subscribe tutorial on official ROS page. when I run my_subscriber no window popup appears. I type -
rosrun image_transport_tutorial my_subscriber
output is -
init done
opengl support available
And then nothing happens. (even the output "init done" is unexplained because there is not output line in my_subscriber.cpp)
I am following this tutorial - ROS tutorial
I have roscore and rosrun image_transport_tutorial my_publisher pathtofile already running in dofferent terminals.
I checked that publisher is publishing by running command
rostopic list -v
my_subscriber file has the following contents -
#include <ros/ros.h>
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <stdio.h>
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
try
{
cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
}
}
int main(int argc, char **argv)
{
std::cout<<"kapil";
ros::init(argc, argv, "image_listener");
ros::NodeHandle nh;
cv::namedWindow("view");
cv::startWindowThread();
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback);
ros::spin();
cv::destroyWindow("view");
}
Solved : I added waitKey function in the try block as suggested in one of the answers.
cv::waitKey(30);
According to the comment to this answer, using cv::startWindowThread() does not always work. Maybe this is the issue in your case.
Try to add cv::waitKey(10) after cv::imshow instead. This will wait for some key press for 10 milliseconds, giving the window time to show the image.
(This always seemed to me like a dirty hack, but it is the common way to show images in OpenCV...)

opencv 2.4.6: can't open the webcam, invalid exception handler (Windows 7, VS2013)

I have a problem in opening my usb webcam using opencv, actually I can't even open the webcam. For instance also the following code doesn't work:
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/legacy/legacy.hpp"
using namespace cv;
using namespace std;
int main(void){
VideoCapture c(0);
}
The error has this form:
"First-chance exception at 0x775370CF (ntdll.dll) in blabla.exe: 0xC0000008: An invalid handle was specified."
I'm in debug mode (it has the same result in release mode) and i'm using pre-compiled opencv libs (that I guess had been compiled with VS2012). I have no idea.
As it is said in http://www.mattmontag.com/development/notes-on-using-opencv-2-3-with-visual-studio-2010
"If everything compiles and then you get runtime errors at the first instance of an OpenCV function call, something like this:
First-chance exception at 0x7c90e4ff in OpenCVHello.exe: 0xC0000008: An invalid handle was specified.
This might be a bug in the OpenCV build, I don't know. You can disable it by going to Debug > Exceptions, unfold Win32 exceptions, and uncheck 0xC0000008."

webcam usage in opencv

I am new with opencv.
I want to capture images from webcam (intex it-105wc).
I am using Microsoft visual c++ 2008 express edition on windows xp.
There is no problem with build solution, but when i try to debug the code it gives following (this happens wwhile executing cvCaptureFromCAM(CV_CAP_ANY);)
Loaded C:\Program Files\Common Files\Ahead\DSFilter\NeVideo.ax, Binary was not built with debug information.
and then exits the code.
so, is there any problem with my code or is it compatibility issue with webcam??
#include "stdafx.h"
#include<stdio.h>
#include <cv.h>
#include <highgui.h>
void main(int argc,char *argv[])
{
int c;
IplImage* color_img;
CvCapture* cv_cap = cvCaptureFromCAM(CV_CAP_ANY);
if(!cv_cap)
{
printf( "ERROR: Capture is null!\n");
}
cvNamedWindow("Video",0); // create window
for(;;)
{
color_img = cvQueryFrame(cv_cap); // get frame
if(color_img != 0)
cvShowImage("Video", color_img); // show frame
c = cvWaitKey(10); // wait 10 ms or for key stroke
if(c == 27)
break; // if ESC, break and quit
}
/* clean up */
cvReleaseCapture( &cv_cap );
cvDestroyWindow("Video");
}
This error message seems to be related to a video codec from the nero burning tools.
If you do not need this codec, you could just unregister it and see, if that solves your problem.
To do that, execute the following on the commandline:
regsvr32 /u "C:\Program Files\Common Files\Ahead\DSFilter\NeVideo.ax"
You should see the message:
DllUnregisterServer in C:\Program Files\Common Files\Ahead\DSFilter\NeVideo.ax succeeded.
To undo this, execute
regsvr32 "C:\Program Files\Common Files\Ahead\DSFilter\NeVideo.ax"

Resources