I modified the proof-of-concept code to remove any of OpenCV's highgui functions. Even after the change, I am experiencing crashes when cvCvtColor is called in the timerEvent. I also tried eliminating the timer event and using a single shot timer, but I am having the same results: without a call to cvCvtColor, the program operates correctly, as soon as cvCvtColor is called when triggered by a timer, an access violation occurs. Really baffled by all of this.
Here is the simple code w/o any highgui functions:
CvDebug.pro
INCLUDEPATH += C:\OpenCV\include\opencv
LIBS += -L"C:\OpenCV\lib" -lcv200 -lcxcore200
INCLUDEPATH += C:\OpenCV\include\opencv
LIBS += -L"C:\OpenCV\lib" -lcv200 -lcxcore200
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QtGui/QApplication>
#include <qtimer.h>
#include "CvDebug.h"
int main(int argc, char **argv)
{
CvDebug w;
QTimer::singleShot( 1000,
&w,
SLOT(ConvertColor
()) );
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include <qtimer.h>
#include "CvDebug.h"
int main(int argc, char **argv)
{
QApplication a(argc, argv);
CvDebug w;
QTimer::singleShot( 1000, &w, SLOT(ConvertColor()) );
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
CvDebug.h
#ifndef CVDEBUG_H
#define CVDEBUG_H
#include <QtGui/QMainWindow>
#include <QImage>
#include <cv.h>
{
Q_OBJECT
public:
~CvDebug();
IplImage* ConvertToIplImage();
public slots:
void ConvertColor();
};
#endif // CVDEBUG_H
#ifndef CVDEBUG_H
#define CVDEBUG_H
#include <QtGui/QMainWindow>
#include <QImage>
#include <cv.h>
class CvDebug : public QMainWindow
{
Q_OBJECT
public:
CvDebug(QWidget *parent = 0);
~CvDebug();
QImage* qimage;
IplImage* ConvertToIplImage();
public slots:
void ConvertColor();
};
#endif // CVDEBUG_H
To copy to clipboard, switch view to plain text mode
CvDebug.cpp
#include "CvDebug.h"
#include <cv.h>
#include <cxcore.h>
{
qimage
= new QImage("test_pic.jpg");
}
CvDebug::~CvDebug()
{
delete qimage;
}
void CvDebug::ConvertColor()
{
IplImage* image = ConvertToIplImage();
IplImage* grayImage = cvCreateImage( cvGetSize(image), IPL_DEPTH_8U, 1);
cvCvtColor( image, grayImage, CV_BGR2GRAY );
cvReleaseImage( &image );
cvReleaseImage( &grayImage );
}
IplImage* CvDebug::ConvertToIplImage()
{
IplImage* image = cvCreateImage( cvSize(qimage->width(), qimage->height()), IPL_DEPTH_8U, 3 );
int cvIndex = 0, cvLineStart = 0;
for(int y=0; y<qimage->height(); y++)
{
cvIndex = cvLineStart;
for(int x=0; x<qimage->width(); x++)
{
image->imageData[cvIndex+0] = qBlue(qimage->pixel(x,y));
image->imageData[cvIndex+1] = qGreen(qimage->pixel(x,y));
image->imageData[cvIndex+2] = qRed(qimage->pixel(x,y));
cvIndex += 3;
}
cvLineStart += image->widthStep;
}
return image;
}
#include "CvDebug.h"
#include <cv.h>
#include <cxcore.h>
CvDebug::CvDebug(QWidget *parent) : QMainWindow(parent)
{
qimage = new QImage("test_pic.jpg");
}
CvDebug::~CvDebug()
{
delete qimage;
}
void CvDebug::ConvertColor()
{
IplImage* image = ConvertToIplImage();
IplImage* grayImage = cvCreateImage( cvGetSize(image), IPL_DEPTH_8U, 1);
cvCvtColor( image, grayImage, CV_BGR2GRAY );
cvReleaseImage( &image );
cvReleaseImage( &grayImage );
}
IplImage* CvDebug::ConvertToIplImage()
{
IplImage* image = cvCreateImage( cvSize(qimage->width(), qimage->height()), IPL_DEPTH_8U, 3 );
int cvIndex = 0, cvLineStart = 0;
for(int y=0; y<qimage->height(); y++)
{
cvIndex = cvLineStart;
for(int x=0; x<qimage->width(); x++)
{
image->imageData[cvIndex+0] = qBlue(qimage->pixel(x,y));
image->imageData[cvIndex+1] = qGreen(qimage->pixel(x,y));
image->imageData[cvIndex+2] = qRed(qimage->pixel(x,y));
cvIndex += 3;
}
cvLineStart += image->widthStep;
}
return image;
}
To copy to clipboard, switch view to plain text mode
Bookmarks