图片格式 jpg到ppm c++代码

// ipgToppm.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"    
#include     
#include     
#include     
#include     
#include     
using namespace std;   
   
void jpg2ppm(char* input, char* output)   
{   
 IplImage* jpg;   
 jpg = cvLoadImage(input, -1);   
 uchar ptrBlue, ptrGreen, ptrRed;   
    
 ofstream pppp;   
 ofstream ppm(output, ios::app | ios::binary);   
 ppm<<"P6"<width<<" "<height<height; j++)   
  for(int i = 0; iwidth ; i++)     
  {   
   uchar* temp_ptr = &((uchar*)(jpg->imageData + jpg->widthStep*j))[i*3];   
   ptrBlue = temp_ptr[0];   
   ptrGreen = temp_ptr[1];   
   ptrRed = temp_ptr[2];   
   
   ppm << ptrRed << ptrGreen << ptrBlue;   
  }   
   
 ppm.close();   
}   
   
int _tmain(int argc, _TCHAR* argv[])   
{   
    jpg2ppm("0.jpg","0.ppm");   
    return 0;   
} 


 

你可能感兴趣的:(机器视觉)