示例#1
0
int main()
{  
	int width ;
	int height;

	// parse pgm header	
	int src_pgm_header_len=read_pgm_header(src_pgm_file,width,height);
	if (src_pgm_header_len==0) return -1;
	//width = 176;	height= 144;
	
	nm8u* src=nmppsAddr_8u((nm8u*)src_pgm_file,src_pgm_header_len);
	int dst_pgm_header_len=save_pgm_header(dst_pgm_file,width,height," Created By RC-Module(2015)");
	nm8u* dst=nmppsAddr_8u((nm8u*)dst_pgm_file,dst_pgm_header_len);
	
	// Sobel filtration
	SobelCuts sobel;
	if (sobel.initAlloc(width, height,30))
		return -1;
	clock_t t0=clock();
	sobel.filter(src,dst);
	clock_t t1=clock();

	sobel.free();
	return t1-t0; 
} 
示例#2
0
文件: pgm.cpp 项目: dmishin/ifs
void read_pgm( std::istream &ifile, MonochromeImageWriter &pixels )
{
  size_t w, h, maxcolor;
  read_pgm_header( ifile, w, h, maxcolor );
  if (maxcolor > 255)
    throw std::logic_error( "only 8-bit supported");
  if (w ==0 || h==0 )
    throw std::logic_error( "zero size of image");
  pixels.set_size(w,h);

  std::cerr<<"Reading image "<<w<<"x"<<h<<" with "<<maxcolor<<" colors\n";
  const size_t BUF_SIZE=1024;
  unsigned char buffer[BUF_SIZE];

  size_t sz = w*h;
  size_t nLeft = sz;
  while (ifile && (nLeft != 0)){
    ifile.read((char *)buffer, std::min(BUF_SIZE, nLeft));
    size_t nRead = ifile.gcount();
    pixels.write_pixels(buffer, nRead);
    nLeft -= nRead;
  }
  if (nLeft != 0)
	  throw std::logic_error("Premature end of file");
}
示例#3
0
int main()
{
    int width ;
    int height;

    // parse pgm header
    int src_pgm_header_len=read_pgm_header(src_pgm_file,width,height);
    if (src_pgm_header_len==0) {
        width=128;	// use default value if pgm-header is invalid
        height=128;	// use default value if pgm-header is invalid
    }
    nm8u* src=nmppsAddr_8u((nm8u*)src_pgm_file,src_pgm_header_len);
    int dst_pgm_header_len=save_pgm_header(dst_pgm_file,width,height," Created By RC-Module(2015)");
    nm8u* dst=nmppsAddr_8u((nm8u*)dst_pgm_file,dst_pgm_header_len);

    // Sobel filtration
    CBaseSobel sobel(width, height);
    if (!sobel.isReady) return -1;
    clock_t t0=clock();
    sobel.filter(src,dst);
    clock_t t1=clock();

    return t1-t0;
}