I'm trying to use Parent mode in OpenCV. It seems that OpenCV is ignoring the cvSetErrMode() call.
fprintf(stderr, "cvSetErrMode(%d) returned %d\n",
CV_ErrModeParent, cvSetErrMode(CV_ErrModeParent));
fprintf(stderr, "cvGetErrMode() returned %d\n", cvGetErrMode());
This returns:
cvSetErrMode(1) returned 0
cvGetErrMode() returned 0
It seems to me that cvGetErrMode() should return 1.
These functions are deprecated in OpenCV 2.x OpenCV still provides stub implementation for backward compatibility.
Related
I would like to utilize OpenCV's integration of OpenGL/OpenCL to achieve fast distortion of images directly on the GPU while avoiding GPU/CPU image transfers. I can create a cv::ogl::Buffer from an OpenGL buffer object in Qt:
// m_pub is of type QOpenGLBuffer
cv::ogl::Buffer b(512, 512, CV_8UC4, m_pub.bufferId());
But the next line throws an exception:
cv::UMat m = cv::ogl::mapGLBuffer(b);
The error reported by OpenCV was originally:
OpenCV(4.5.5) Error: Unknown error code -220 (OpenCL:
clCreateFromGLBuffer failed) in cv::ogl::mapGLBuffer, file
D:\OpenCV\opencv-4.5.5\modules\core\src\opengl.cpp, line 1886
To get further information, I call cv::ocl::getOpenCLErrorString(status); in opengl.cpp, rebuild, and find that the error is CL_INVALID_CONTEXT.
I've checked cv::ocl::Context, cv::ocl::Device, cv::ocl::Platform, added cv::ocl::attachContext, all doesn't work. I'm stuck here, don't know how to go forward.
Any suggestions are really appreciated. Thanks.
It needs to call cv::ogl::ocl::initializeContextFromGL() in the initialization phase. My project is based on Qt, the window is inherited from QOpenGLWindow, so I call that function in initializeGL().
I guess that without this call, OpenCV would also create an OpenCL context automatically, but that's not the same as the one created from OpenGL, that's why the CL_INVALID_CONTEXT error occurred.
As a reminder, I used cv::remap to process a 512x512 image and found that processing on the GPU via OpenCL was not much faster than on the CPU. It still takes around 12ms on average. This is still too slow if the application requires a high frame rate and needs to leave time for other processing.
I was working with opencv using haarcascade face detection . But this error is creeping and i am not able to get this. So please guide me.
OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
import cv2
def videoCam():
cap=cv2.VideoCapture(0)
face_cascade=cv2.CascadeClassifier("haarcascade_frontalface_alt.xml")
while (True):
ret,frame=cap.read()
gray_frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
if (ret==False):
continue
faces=face_cascade.detectMultiScale(gray_frame,1.3,5)
for(x,y,w,h) in faces:
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
cv2.imshow("Video Frame",frame)
key_pressed=cv2.waitKey(1) & 0xff
if(key_pressed==ord('q')):
break
cap.release()
cv2.destroyAllWindows()
videoCam()
You are getting above error because frame is None in cv2.cvtColor function. Please, verify input to the cv2.VideoCapture function. It's a device index which is just the number to specify which camera. You haven't mentioned above which camera you are using, i.e., internal or external camera. Read about what device index to use from here. You can check if the VideoCapture() method already initializes your camera object using print(cap.isOpened()) after cv2.VideoCapture function. It will return True in case it successfully initialized your camera object.
And, why are doing
if (ret==False):
continue
after cv2.cvtColor. The main aim of this is to check if the frame is read correctly or not. If the image is read correctly, ret will be True, else False. So, you should check this before using cv2.cvtColor function and if it returns False, then you should break from the loop, instead of using continue, otherwise the while loop will keep on running infinitely.
I am new to pthread_create and posix threads, I tried to develop a multi-thread program using pthread_create, but it fails with return value equal to -1. I tried to search what is this error code, but could not find any? Does anyone know what this return code (-1) means?
According to POSIX programming Manual, the return value for the pthread_create functions is:
If successful, the pthread_create() function shall return zero; otherwise, an error number shall be returned to indicate the error.
And the list of possible errors are non-negative.
But, for IBM z/OS, for example, the return value can be -1:
If successful, pthread_create() returns 0.
If unsuccessful, pthread_create() returns -1 and sets errno to one of the following values:
So, I suggest:
provide more context on what's the environment and standard library you use
check the errno variable - it should contain the error code
I just installed OpenCV2.4.2 and created an OpenCV project using CMake. I don't get any compilation errors. I have several functions for processing images and I have 2 applications:
1- Processes data from a video
2- Processes simulated data.
Both applications are identical except from the data extraction from the video.
PROBLEM: The application processing video crashes with
Unhandled exception at 0x75d8a048 in program.exe Access violation
reading location 0x049f08c0.
It crashes in this part of the code, when reading frames:
cv::VideoCapture _video;
while(1)
{
// grab the frame
_video >> frame; <-------------CRASHES HERE
processFrame(frame);
}
So I guess there could be a problem with cv::VideoCapture class in OpenCV 2.4.2. How can I detect the problem and solve it?
EDIT
With video camera I managed to catch the error message:
OpenCV Error: Assertion failed (m.dims >= 2) in unknown function, file ..\..\..\
src\opencv\modules\core\src\matrix.cpp, line 268
OpenCV Error: Assertion failed (0 <= _rowRange.start && _rowRange.start <= _rowR
ange.end && _rowRange.end <= m.rows) in unknown function, file ..\..\..\src\open
cv\modules\core\src\matrix.cpp, line 283
Are you checking if the capture actually opened the file/camera ?
if(_video.isOpened()) { // check if capture succeeded
// do stuff
}
Not all codecs are supported per default. This depends on the library you use underneath to open the video. (This might be ffmpeg or quicktime).
Also you can catch the exception yourself, just to be on the safe side for future problems
try {
_video >> frame;
} catch (cv::Exception) {
cout << "An exception has accurred" << endl;
};
i use this functions to segment characters image ,but the programme crach ,somone can help me please to found solution why it crach?
You need to pinpoint the line that causes the crash. For that I can think in 2 ways:
Use a debugger;
or if you are afraid of that, use the printf() method:
The printf() method involves placing a printf() call after each function call in your program, so when you run your application you can see in the console what was the last printf() message. That will help you locate the code that is responsible for the crash. Example:
printf("dbg10\n");
IplImage *img_cv = cvLoadImage("plaque.jpg");
printf("dbg20\n");
cvSetImageROI(img_cv,cvRect(8,10,60,35));
printf("dbg30\n");
IplImage *img_pl = cvCreateImage( cvGetSize(img_cv),img_cv->depth,img_cv->nChannels);
printf("dbg40\n");
cvCopy(img_cv,img_pl, NULL);
printf("dbg50\n");
cvResetImageROI(img_cv);
printf("dbg60\n");
//etc
From what I saw in your code, the first 2 calls have the potential to crash your application: if cvLoadImage() fails to load an image it will return a NULL pointer. Since the next function receives the pointer as a parameter, it will try to dereference the null pointer and that can a crash. Solution? Always check the freaking return of the calls you make:
IplImage *img_cv = cvLoadImage("plaque.jpg");
if (!img_cv)
{
printf("Failed to load image.\n");
exit(1);
}
cvSetImageROI(img_cv,cvRect(8,10,60,35));