Access violation error on stereolabs - opencv

I'm writing a program to convert an image sensed with a StereoLabs ZED stereocamera to an OpenCV image, to do some processing, here is the code (including the setup part een if I don't know if the problem can be there):
#include "stdafx.h"
#include "sl/camera.hpp"
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
using namespace sl;
cv::Mat zed_to_ocv(sl::Mat zed_mat) {
int cv_type = -1;
switch (zed_mat.getDataType()) {
case MAT_TYPE_32F_C1: cv_type = CV_32FC1; break;
case MAT_TYPE_32F_C2: cv_type = CV_32FC2; break;
case MAT_TYPE_32F_C3: cv_type = CV_32FC3; break;
case MAT_TYPE_32F_C4: cv_type = CV_32FC4; break;
case MAT_TYPE_8U_C1: cv_type = CV_8UC1; break;
case MAT_TYPE_8U_C2: cv_type = CV_8UC2; break;
case MAT_TYPE_8U_C3: cv_type = CV_8UC3; break;
case MAT_TYPE_8U_C4: cv_type = CV_8UC4; break;
default: break;
}
return cv::Mat(zed_mat.getHeight(), zed_mat.getWidth(), cv_type, zed_mat.getPtr<sl::uchar1>(MEM_CPU));
}
int main(int argc, char **argv) {
InitParameters parameters;
parameters.depth_mode = DEPTH_MODE_PERFORMANCE;
parameters.coordinate_units = UNIT_METER;
parameters.camera_fps = 30;
if (argc > 1) {
parameters.svo_input_filename = argv[1];
}
sl::Camera zed;
ERROR_CODE err = zed.open(parameters);
if (err != SUCCESS) {
zed.close();
cout << "Error while opening ZED camera";
return -1;
}
RuntimeParameters runtime_parameters;
runtime_parameters.sensing_mode = SENSING_MODE_STANDARD;
Resolution image_size = zed.getResolution();
int new_width = image_size.width;
int new_height = image_size.height;
sl::Mat image_zed(new_width, new_height, MAT_TYPE_8U_C4);
cv::Mat image_ocv = zed_to_ocv(image_zed);
cv::Mat image(new_width, new_height, CV_8UC1);
while (true) {
if (zed.grab(runtime_parameters) == SUCCESS) {
zed.retrieveImage(image_zed, VIEW_LEFT, MEM_CPU, new_width, new_height);
cv::cvtColor(image_ocv, image, CV_BGRA2GRAY);
imshow("camera", image);
waitKey(30);
}
}
zed.close();
return 0;
}
This code works just fine, but if I wanted to use 32F matrices instead (changing the type of both image_zed and image) I get a
Exception in correspondence of 0x00007FF97D175400 (opencv_imgproc340d.dll) in projectCV.exe: 0xC0000005: access violation error reading 0x000002C52DC13040.
error. I tried changing to
getPtr<sl::float1>
inside zed_to_ocv, but the error is still there.
EDIT: Debugging I found out the crash happens at line
cv::cvtColor(image_ocv, image, CV_BGRA2GRAY);
but I still can't figure out why.
What is the problem here? Thanks.

Related

eps-open-rtos: sdk_wifi_station_get_connect_status returns 255

Even in included HTTP get demo sdk_wifi_station_get_connect_status() returns 255 even before try to connect. And of course it refuses to connect to
There is no any documentation this status.
Is there any suggestion on this issue?
you need to config the esp on user_init() function and call function sdk_wifi_station_get_connect_status() inside a task
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "ssid_config.h"
#include "esp8266.h"
void task1(void *pvParameters)
{
while (1)
{
check_wifi_connection();
}
}
void check_wifi_connection()
{
uint8_t status = sdk_wifi_station_get_connect_status();
while (status != STATION_GOT_IP)
{
status = sdk_wifi_station_get_connect_status();
vTaskDelay(ONE_SEC / portTICK_PERIOD_MS);
switch (status)
{
case STATION_WRONG_PASSWORD:
printf("WiFi: wrong password\n\r");
break;
case STATION_NO_AP_FOUND:
printf("WiFi: AP not found\n\r");
break;
case STATION_CONNECT_FAIL:
printf("WiFi: connection failed\r\n");
break;
case STATION_GOT_IP:
break;
default:
printf("%s: status = %d\n\r", __func__, status);
break;
}
}
}
void user_init(void)
{
uart_set_baud(0, BAUDRATE);
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_auto_connect(true);
sdk_wifi_station_set_config(&config);// my config that
gpio_enable(gpio, GPIO_INPUT);
tsqueue = xQueueCreate(2, sizeof(uint32_t));
xTaskCreate(&task1,
"task1",
2048,
NULL,
tskIDLE_PRIORITY,
&task_handler);
}

Alternative to waitKey() for updating window in OpenCV

All examples and books I've seen so far recommends using waitKey(1) to force repaint OpenCV window. That looks weird and too hacky. Why wait for even 1ms when you don't have to?
Are there any alternatives? I tried cv::updateWindow but it seems to require OpenGL and therefore crashes. I'm using VC++ on Windows.
I looked in to source and as #Dan Masek said, there doesn't seem to be any other functions to process windows message. So I ended up writing my own little DoEvents() function for VC++. Below is the full source code that uses OpenCV to display video frame by frame while skipping desired number of frames.
#include <windows.h>
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
bool DoEvents();
int main(int argc, char *argv[])
{
VideoCapture cap(argv[1]);
if (!cap.isOpened())
return -1;
namedWindow("tree", CV_GUI_EXPANDED | CV_WINDOW_AUTOSIZE);
double frnb(cap.get(CV_CAP_PROP_FRAME_COUNT));
std::cout << "frame count = " << frnb << endl;
for (double fIdx = 0; fIdx < frnb; fIdx += 50) {
Mat frame;
cap.set(CV_CAP_PROP_POS_FRAMES, fIdx);
bool success = cap.read(frame);
if (!success) {
cout << "Cannot read frame " << endl;
break;
}
imshow("tree", frame);
if (!DoEvents())
return 0;
}
return 0;
}
bool DoEvents()
{
MSG msg;
BOOL result;
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
result = ::GetMessage(&msg, NULL, 0, 0);
if (result == 0) // WM_QUIT
{
::PostQuitMessage(msg.wParam);
return false;
}
else if (result == -1)
return true; //error occured
else
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
return true;
}

Running Programs in MathGL

I'm trying to run one of the examples using FLTK in Mathgl. While basic programs will compile without error, I seem to be getting a linker error when compiling FLTK_MathGL examples.
This is the error portion I get from my build log.
C:\mathgl-2.3\src\libmgl.dll.a C:\mathgl-2.3\widgets\libmgl-fltk.a -mwindows
obj\Release\main.o:main.cpp:(.text$_ZN7mglFLTK3RunEv[__ZN7mglFLTK3RunEv]+0x1): undefined reference to "_imp__mgl_fltk_run'
obj\Release\main.o:main.cpp:(.text$_ZN7mglFLTKC1EPFiP8mglGraphEPKc[__ZN7mglFLTKC1EPFiP8mglGraphEPKc]+0x39): undefined reference to "_imp___ZTV7mglFLTK'
c:/codeblocks/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: obj\Release\main.o: bad reloc address 0x39 in section ".text$_ZN7mglFLTKC1EPFiP8mglGraphEPKc[__ZN7mglFLTKC1EPFiP8mglGraphEPKc]'
c:/codeblocks/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
2 error(s), 0 warning(s) (0 minute(s), 3 second(s))
I'm not sure what else I can do. I have pasted the program below.
#define MGL_HAVE_FLTK
#include "mgl2/fltk.h"
//-----------------------------------------------------------------------------
#if defined(WIN32) || defined(_MSC_VER) || defined(__BORLANDC__)
#include <windows.h>
#else
#include <unistd.h>
#endif
void long_calculations() // just delay which correspond to simulate calculations
{
#if defined(WIN32) || defined(_MSC_VER) || defined(__BORLANDC__)
Sleep(1000);
#else
sleep(1); // which can be very long
#endif
}
//-----------------------------------------------------------------------------
#if defined(PTHREAD_SAMPLE1) // first variant of multi-threading usage of mglFLTK window
mglFLTK *gr=NULL;
void *calc(void *)
{
mglPoint pnt;
for(int i=0;i<10;i++) // do calculation
{
long_calculations(); // which can be very long
pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1);
if(gr)
{
gr->Clf(); // make new drawing
gr->Line(mglPoint(),pnt,"Ar2");
char str[10] = "i=0"; str[2] = '0'+i;
gr->Puts(mglPoint(),str);
gr->Update(); // update window
}
}
exit(0);
}
int main(int argc,char **argv)
{
static pthread_t thr;
pthread_create(&thr,0,calc,0);
pthread_detach(thr);
gr = new mglFLTK;
gr->Run(); return 0;
}
#elif defined(PTHREAD_SAMPLE2) // another variant of multi-threading usage of mglFLTK window. Work only if pthread was enabled for MathGL
mglPoint pnt; // some global variable for changeable data
int main(int argc,char **argv)
{
mglFLTK gr("test");
gr.RunThr(); // <-- need MathGL version which use pthread
for(int i=0;i<10;i++) // do calculation
{
long_calculations();// which can be very long
pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1);
gr.Clf(); // make new drawing
gr.Line(mglPoint(),pnt,"Ar2");
char str[10] = "i=0"; str[3] = '0'+i;
gr.Update(); // update window
}
return 0; // finish calculations and close the window
}
#else // just default samples
int test_wnd(mglGraph *gr);
int sample(mglGraph *gr);
int sample_1(mglGraph *gr);
int sample_2(mglGraph *gr);
int sample_3(mglGraph *gr);
int sample_d(mglGraph *gr);
//-----------------------------------------------------------------------------
int main(int argc,char **argv)
{
mglFLTK *gr;
char key = 0;
if(argc>1) key = argv[1][0]!='-' ? argv[1][0]:argv[1][1];
else printf("You may specify argument '1', '2', '3' or 'd' for viewing examples of 1d, 2d, 3d or dual plotting\n");
switch(key)
{
case '0': gr = new mglFLTK((mglDraw *)NULL,"1D plots"); break;
case '1': gr = new mglFLTK(sample_1,"1D plots"); break;
case '2': gr = new mglFLTK(sample_2,"2D plots"); break;
case '3': gr = new mglFLTK(sample_3,"3D plots"); break;
case 'd': gr = new mglFLTK(sample_d,"Dual plots");break;
case 't': gr = new mglFLTK(test_wnd,"Testing"); break;
default: gr = new mglFLTK(sample,"Drop and waves"); break;
}
if(key=='0')
{ gr->Rotate(40,60); gr->Box(); gr->Light(true); gr->FSurf("sin(4*pi*x*y)"); gr->Update(); }
gr->Run(); return 0;
}
#endif
//-----------------------------------------------------------------------------

how to draw curve on control points using opencv

I want to draw curve on control points so that I can move the curve to change the colours , below is the code , getting help from a very well explained answer
const int N=5; // number of control points (must be >= 4)
float ctrl[N]= // control points y values initiated with linear function y=x
{ // x value is index*1.0/(N-1)
0.00,
0.25,
0.50,
0.75,
1.00,
};
float correction(float col,float *ctrl,int n)
{
float di=1.0/float(n-1);
int i0,i1,i2,i3;
float t,tt,ttt;
float a0,a1,a2,a3,d1,d2;
// find start control point
col*=float(n-1);
i1=col; col-=i1;
i0=i1-1;
i2=i1+1; if (i2>=n) i2=n-1;
i3=i1+2;
// compute interpolation coefficients
if (i0>=0) d1=0.5*(ctrl[i2]-ctrl[i0]); else d1=ctrl[i2]-ctrl[i1];
if (i3< n) d2=0.5*(ctrl[i3]-ctrl[i1]); else d2=ctrl[i2]-ctrl[i1];
a0=ctrl[i1];
a1=d1;
a2=(3.0*(ctrl[i2]-ctrl[i1]))-(2.0*d1)-d2;
a3=d1+d2+(2.0*(-ctrl[i2]+ctrl[i1]));
// now interpolate new colro intensity
t=col; tt=t*t; ttt=tt*t;
t=a0+(a1*t)+(a2*tt)+(a3*ttt);
return t;
}
int main (int argc, const char** argv)
{
Mat input = imread ("E:\\img2.jpg");
Mat input1 = input;
for(int i=0 ; i<input1.rows ; i++)
{
for (int p=0;p<input1.cols;p++)
{
input1.at<cv::Vec3b>(i,p)[0] = 255*correction(input1.at<cv::Vec3b>(i,p)[0]/255.0,ctrl,N); //B
input1.at<cv::Vec3b>(i,p)[1] = 255*correction(input1.at<cv::Vec3b>(i,p)[1]/255.0,ctrl,N); //G
input1.at<cv::Vec3b>(i,p)[2] = 255*correction(input1.at<cv::Vec3b>(i,p)[2]/255.0,ctrl,N); //R
}
}
imshow("image" , input);
waitKey();
}
But the required output is like the curve the program is working , but the curves are not drawing on my screen like below , how to draw them using opencv or other approach So that these lines can play the role of their specific colour in image and with their values , like below right one is the orignal image and left one is the result of changing values through cuves , below curves are the control points per B,G,R
This code sketch allows you to edit spline with mouse it uses the files from this link (attach to your project: overhauser.cpp overhauser.hpp and vec3.hpp):
Left mouse button adds/moves a point, right removes.
#include <iostream>
#include <vector>
#include <stdio.h>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cstddef>
#include "opencv2/opencv.hpp"
#include <iostream>
#include <fstream>
#include "overhauser.hpp"
using namespace std;
using namespace cv;
Mat result;
Mat Img;
int current_color=0;
vector<cv::Point2f> pts_red;
vector<cv::Point2f> pts_green;
vector<cv::Point2f> pts_blue;
Mat curvesImg;
int selectedPt=-1;
CRSpline* spline_red = 0;
CRSpline* spline_green = 0;
CRSpline* spline_blue = 0;
unsigned char LUT_RED[256];
unsigned char LUT_GREEN[256];
unsigned char LUT_BLUE[256];
// comparison function:
bool mycomp (Point2f p1, Point2f p2)
{
return p1.x<p2.x;
}
float dist(Point2f p1,Point2f p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
int findNEarestPt(Point2f pt, float maxDist)
{
vector<Point2f> current_pts_set;
current_color=0;
if(pt.x>255 && pt.x<512)
{
current_color=1;
}
if(pt.x>=512)
{
current_color=2;
}
float ptx=pt.x;
switch(current_color)
{
case 0:
current_pts_set=pts_red;
break;
case 1:
current_pts_set=pts_green;
pt.x-=255;
break;
case 2:
current_pts_set=pts_blue;
pt.x-=511;
break;
}
float minDist=FLT_MAX;
int ind=-1;
for(int i=0;i<current_pts_set.size();++i)
{
float d=dist(pt,current_pts_set[i]);
if(minDist>d)
{
ind=i;
minDist=d;
}
}
if(minDist>maxDist)
{
ind=-1;
}
return ind;
}
float F(float t,float x, CRSpline* spline)
{
vec3 rv = spline->GetInterpolatedSplinePoint(t);
return x-rv.x;
}
float solveForX(float x,CRSpline* slpine)
{
float a=-1.0f,b=1.0,c,e=1e-2;
c=(a+b)/2;
while( (fabs(b-a)>e) && (F(c,x,slpine)!=0) )
{
if (F(a,x,slpine)*F(c,x,slpine)<0)
{
b=c;
}
else
{
a=c;
}
c=(a+b)/2;
}
return c;
}
int ind=-1;
void mouseHandler(int event, int x, int y, int flags, void* param)
{
Point2f m;
m.x=x;
m.y=y;
curvesImg=Scalar(0,0,0);
switch (event)
{
case cv::EVENT_RBUTTONDOWN:
ind=findNEarestPt(m,5);
if (ind==-1)
{
}else
{
switch(current_color)
{
case 0:
pts_red.erase(pts_red.begin()+ind);
break;
case 1:
pts_green.erase(pts_green.begin()+ind);
break;
case 2:
pts_blue.erase(pts_blue.begin()+ind);
break;
}
ind=-1;
}
break;
case cv::EVENT_LBUTTONDOWN:
ind=findNEarestPt(m,5);
if (ind==-1)
{
switch(current_color)
{
case 0:
pts_red.push_back(m);
selectedPt=pts_red.size()-1;
break;
case 1:
pts_green.push_back(Point2f(m.x-255.0,m.y));
selectedPt=pts_green.size()-1;
break;
case 2:
pts_blue.push_back(Point2f(m.x-511,m.y));
selectedPt=pts_blue.size()-1;
break;
}
}else
{
selectedPt=ind;
}
break;
case cv::EVENT_MOUSEMOVE:
if(ind!=-1)
{
switch(current_color)
{
case 0:
pts_red[selectedPt].x=m.x;
pts_red[selectedPt].y=m.y;
break;
case 1:
pts_green[selectedPt].x=m.x-255;
pts_green[selectedPt].y=m.y;
break;
case 2:
pts_blue[selectedPt].x=m.x-511;
pts_blue[selectedPt].y=m.y;
break;
}
}
break;
case cv::EVENT_LBUTTONUP:
ind=-1;
break;
}
std::sort(pts_red.begin(),pts_red.end(),mycomp);
if(pts_red.size()>0)
{
pts_red[pts_red.size()-1].x=255;
pts_red[0].x=0;
}
std::sort(pts_green.begin(),pts_green.end(),mycomp);
if(pts_green.size()>0)
{
pts_green[pts_green.size()-1].x=255;
pts_green[0].x=0;
}
std::sort(pts_blue.begin(),pts_blue.end(),mycomp);
if(pts_blue.size()>0)
{
pts_blue[pts_blue.size()-1].x=255;
pts_blue[0].x=0;
}
for(int i=0;i<pts_red.size();++i)
{
circle(curvesImg,pts_red[i],5,Scalar(0,0,255),-1,CV_AA);
}
for(int i=0;i<pts_green.size();++i)
{
circle(curvesImg,Point2f(pts_green[i].x+255,pts_green[i].y),5,Scalar(0,255,0),-1,CV_AA);
}
for(int i=0;i<pts_blue.size();++i)
{
circle(curvesImg,Point2f(pts_blue[i].x+511,pts_blue[i].y),5,Scalar(255,0,0),-1,CV_AA);
}
if (spline_red) {delete spline_red;}
spline_red = new CRSpline();
if (spline_green) {delete spline_green;}
spline_green = new CRSpline();
if (spline_blue) {delete spline_blue;}
spline_blue = new CRSpline();
for (int i=0;i<pts_red.size();++i)
{
vec3 v(pts_red[i].x,pts_red[i].y,0);
spline_red->AddSplinePoint(v);
}
for (int i=0;i<pts_green.size();++i)
{
vec3 v(pts_green[i].x,pts_green[i].y,0);
spline_green->AddSplinePoint(v);
}
for (int i=0;i<pts_blue.size();++i)
{
vec3 v(pts_blue[i].x,pts_blue[i].y,0);
spline_blue->AddSplinePoint(v);
}
vec3 rv_last(0,0,0);
if(pts_red.size()>2)
{
for(int i=0;i<256;++i)
{
float t=solveForX(i,spline_red);
vec3 rv = spline_red->GetInterpolatedSplinePoint(t);
if(rv.y>255){rv.y=255;}
if(rv.y<0){rv.y=0;}
unsigned char I=(unsigned char)(rv.y);
LUT_RED[i]=255-I;
if(i>0)
{
line(curvesImg,Point(rv.x,rv.y),Point(rv_last.x,rv_last.y),Scalar(0,0,255),1);
}
rv_last=rv;
}
}
rv_last=vec3(0,0,0);
if(pts_green.size()>2)
{
for(int i=0;i<256;++i)
{
float t=solveForX(i,spline_green);
vec3 rv = spline_green->GetInterpolatedSplinePoint(t);
if(rv.y>255){rv.y=255;}
if(rv.y<0){rv.y=0;}
unsigned char I=(unsigned char)(rv.y);
LUT_GREEN[i]=255-I;
if(i>0)
{
line(curvesImg,Point(rv.x+255,rv.y),Point(rv_last.x+255,rv_last.y),Scalar(0,255,0),1);
}
rv_last=rv;
}
}
rv_last=vec3(0,0,0);
if(pts_blue.size()>2)
{
for(int i=0;i<256;++i)
{
float t=solveForX(i,spline_blue);
vec3 rv = spline_blue->GetInterpolatedSplinePoint(t);
if(rv.y>255){rv.y=255;}
if(rv.y<0){rv.y=0;}
unsigned char I=(unsigned char)(rv.y);
LUT_BLUE[i]=255-I;
if(i>0)
{
line(curvesImg,Point(rv.x+511,rv.y),Point(rv_last.x+511,rv_last.y),Scalar(255,0,0),1);
}
rv_last=rv;
}
}
int cur_col=0;
if(m.x>255 && m.x<512)
{
cur_col=1;
}
if(m.x>=512)
{
cur_col=2;
}
Scalar col;
switch(cur_col)
{
case 0:
col=Scalar(0,0,255);
break;
case 1:
col=Scalar(0,255,0);
break;
case 2:
col=Scalar(255,0,0);
break;
}
line(curvesImg,Point(0,m.y),Point(curvesImg.cols,m.y),col,1);
line(curvesImg,Point(m.x,0),Point(m.x,curvesImg.rows),col,1);
imshow("Correction curves",curvesImg);
vector<Mat> ch;
cv::split(Img,ch);
LUT(ch[0],Mat(256,1,CV_8UC1,LUT_BLUE),ch[0]);
LUT(ch[2],Mat(256,1,CV_8UC1,LUT_RED),ch[2]);
LUT(ch[1],Mat(256,1,CV_8UC1,LUT_GREEN),ch[1]);
cv::merge(ch,result);
imshow("Transformed",result);
}
// ---------------------------------
//
// ---------------------------------
//==============================================================================
int main( int argc, char** argv )
{
for (int i=0;i<256;++i)
{
LUT_RED[i]=i;
LUT_GREEN[i]=i;
LUT_BLUE[i]=i;
}
namedWindow("Image");
namedWindow("Correction curves");
namedWindow("Transformed");
Img=imread("D:\\ImagesForTest\\lena.jpg",1);
imshow("Image",Img);
curvesImg=Mat::zeros(256,768,CV_8UC3);
setMouseCallback("Correction curves", mouseHandler, NULL);
waitKey(0);
getchar();
}

access webcam fail

i am still new on opencv, i make simple program based on sample to access webcam but always fails. i change variable id to 0,1,2...100 but i got same result. this is my program:
#include "cv.h"
#include "highgui.h"
#include "stdio.h"
#include "iostream"
// A Simple Camera Capture Framework
int main()
{
IplImage* img = NULL;
CvCapture* cap = NULL;
int id=0;
cap = cvCaptureFromCAM(id);
cvNamedWindow("Images",CV_WINDOW_AUTOSIZE);
if ( !cap )
printf("ERROR\n\n");
else
for(;;)
{
img = cvQueryFrame(cap);
cvShowImage("Imagenes", img);
cvWaitKey(10);
}
cvReleaseImage(&img);
cvReleaseCapture(&cap);
return 0;
}
thank you for your help
Do yourself a favor and check the return of the functions. Maybe some of them are failing and you'll never know why.
Another tip: try with id = -1.
#include <iostream>
#include <sstream>
#include <string>
#include <cv.h>
#include <highgui.h>
int main()
{
CvCapture* capture = NULL;
if ((capture = cvCaptureFromCAM(-1)) == NULL)
{
fprintf(stderr, "ERROR: capture is NULL \n");
return -1;
}
cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);
cvQueryFrame(capture); // Sometimes needed to get correct data
IplImage* frame = NULL;
while (1)
{
if ((frame = cvQueryFrame(capture)) == NULL)
{
fprintf( stderr, "ERROR: cvQueryFrame failed\n");
break;
}
if (frame == NULL)
{
usleep(100000);
continue;
}
cvShowImage("mywindow", frame); // Do not release the frame!
int key = cvWaitKey(10);
if (key == 27) // ESC was pressed
break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("mywindow");
return 0;
}

Resources