opencv c++ 用ofstream写文件的问题
voidreadpixelvalue(IplImage*grayImg8u){char*c=newchar;itoa(coord_number,c,10);coord_f...
void readpixelvalue(IplImage* grayImg8u){
char *c = new char;
itoa(coord_number, c, 10);
coord_file = "C:/Users/Xtrong/Desktop/test/pixel/coord_file"+string(c) +".txt";
ofstream ofs(coord_file.c_str());
CvScalar pixel;
for (int i=0; i<grayImg8u->height; i++)
{
for (int j=0; j<grayImg8u->width; j++)
{
pixel = cvGet2D(grayImg8u, i, j);
cout<<pixel.val[0];
ofs<<pixel.val[0]<<setw(5);
}
cout<<endl;
}
coord_number++;
cout<<"一帧结束 !!!"<<endl;
//delete c;
}
//*/
//
int main( int argc, char** argv )
{
IplImage* lpMthImg1 = cvCreateImage( cvSize(255,255), 8, 3 );
cvNamedWindow("video", 1);
cvMoveWindow("video", 30, 0);
pMthImg1 = cvLoadImage("C:\\Users\\Xtrong\\Desktop\\test\\03.png",1);
if( !pMthImg1 )
cout<<"加载失败"<<endl;
else
readpixelvalue( pMthImg1 );//问题出现的函数
cvShowImage("video", pFrame);
cvDestroyWindow("video");
cvReleaseImage(&pMthImg1);
cvReleaseCapture(&pCapture);
return 0;
}
ofstream ofs(coord_file.c_str()); //确实生成了一个TXT文件
cout<<pixel.val[0]; //这个pixel.val[0]里确实是有值的,能打印出来
ofs<<pixel.val[0]<<setw(5); //这里怎么也写不到TXT里去
求解释 展开
char *c = new char;
itoa(coord_number, c, 10);
coord_file = "C:/Users/Xtrong/Desktop/test/pixel/coord_file"+string(c) +".txt";
ofstream ofs(coord_file.c_str());
CvScalar pixel;
for (int i=0; i<grayImg8u->height; i++)
{
for (int j=0; j<grayImg8u->width; j++)
{
pixel = cvGet2D(grayImg8u, i, j);
cout<<pixel.val[0];
ofs<<pixel.val[0]<<setw(5);
}
cout<<endl;
}
coord_number++;
cout<<"一帧结束 !!!"<<endl;
//delete c;
}
//*/
//
int main( int argc, char** argv )
{
IplImage* lpMthImg1 = cvCreateImage( cvSize(255,255), 8, 3 );
cvNamedWindow("video", 1);
cvMoveWindow("video", 30, 0);
pMthImg1 = cvLoadImage("C:\\Users\\Xtrong\\Desktop\\test\\03.png",1);
if( !pMthImg1 )
cout<<"加载失败"<<endl;
else
readpixelvalue( pMthImg1 );//问题出现的函数
cvShowImage("video", pFrame);
cvDestroyWindow("video");
cvReleaseImage(&pMthImg1);
cvReleaseCapture(&pCapture);
return 0;
}
ofstream ofs(coord_file.c_str()); //确实生成了一个TXT文件
cout<<pixel.val[0]; //这个pixel.val[0]里确实是有值的,能打印出来
ofs<<pixel.val[0]<<setw(5); //这里怎么也写不到TXT里去
求解释 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询