This code has really been used so far. I have no idea what causes him to throw an error now (I really donโt remember making any changes to the code). Here it is (it reads the image from the file into an OpenCV IplImage object and then converts it to a jpeg buffer):
IplImage* fIplImageHeader = cvLoadImage( filePath.c_str() );
vector<int> p;
p.push_back( CV_IMWRITE_JPEG_QUALITY );
p.push_back( 75 );
vector<unsigned char> buf;
cv::imencode( ".jpg", fIplImageHeader, buf, p );
Full error:
Unhandled exception at 0x638fee22 in Client.exe: 0xC0000005: Access violation reading location 0x02176000.
There is a valid image in fIplImageHeader that I can confirm using:
cvShowImage( "Window", fIplImageHeader );
EDIT:
Longer snippet:
while ( l < 30 )
{
std::stringstream sstm;
string filePath;
sstm << workingDirectory << "/temp/" << k << ".jpg";
filePath = sstm.str();
cout << filePath.c_str() << endl;
IplImage* fIplImageHeader = cvLoadImage( filePath.c_str() );
vector<int> p;
p.push_back( CV_IMWRITE_JPEG_QUALITY );
p.push_back( 75 );
vector<unsigned char> buf;
cv::imencode( ".jpg", fIplImageHeader, buf, p );
k++;
l++;
if (10 == k)
{
k = 0;
}
char key = cvWaitKey( 1000/30 );
cvReleaseImage( &fIplImageHeader );
}
source
share