⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vlimage.cpp

📁 hough变换的代码
💻 CPP
字号:
// vlImage.cpp: implementation of the CvlImage class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "airImg.h"
#include "vlImage.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CvlImage::CvlImage()
{
	pixel = NULL;
}

CvlImage::~CvlImage()
{
	if (pixel)
		delete pixel;
}

void CvlImage::vlImageCreate(vlImageFormat imgFormat, int imgWidth, int imgHeight, vlPixel *imgPixel)
{
	int size;

	switch(imgFormat) {
	case NONE:
		size = VL_NONE_SIZE(imgWidth, imgHeight);
		break;
	case RGB:
		size = VL_RGB_SIZE(imgWidth, imgHeight);
		break;
	case HSI:
		size = VL_HSI_SIZE(imgWidth, imgHeight);
		break;
	case GRAY:
		size = VL_GRAY_SIZE(imgWidth, imgHeight);
		break;
	case BINARY:
		size = VL_BINARY_SIZE(imgWidth, imgHeight);
		break;
	default:
		MessageBox(NULL,"unsupported image format","warnning!",MB_OK);
		return;
	}

	/* initialize instances */
	if (pixel=new vlPixel[size])
	{
		format = imgFormat;
		height = imgHeight;
		width = imgWidth;
		memcpy(pixel,imgPixel,size);
	}
	return;
}

/* initialize an existing image */
int CvlImage::vlImageInit (CvlImage *image, vlImageFormat format, int width, int height)
{
  int size;

  if (!image) {
	MessageBox(NULL,"NULL image\n","warnning",MB_OK);
    return (-1);		/* failure */
  }

  switch (format) {
  case NONE:
    size = VL_NONE_SIZE (width, height);
    break;

  case RGB:
    size = VL_RGB_SIZE (width, height);
    break;

  case HSI:
    size = VL_HSI_SIZE (width, height);
    break;

  case GRAY:
    size = VL_GRAY_SIZE (width, height);
    break;

  case BINARY:
    size = VL_BINARY_SIZE (width, height);
    break;

  default:
	MessageBox(NULL,"unsupported image format\n","warnning",MB_OK);
    return (-1);		/* failure */
  }

  image->format = format;
  image->width = width;
  image->height = height;

  if (!(image->pixel = new vlPixel[size])) {
    MessageBox(NULL,"malloc failed","warnning",MB_OK);
    return (-1);		/* failure */
  }
  
  return (0);			/* success */
}

int CvlImage::vlImageCopy (CvlImage *src, CvlImage *dest)
{
  int size, width, height;

  if ((!src) || (!dest)) {
    MessageBox(NULL, "NULL image\n", "warnning", MB_OK);
    return (-1);		/* failure */
  }

  width = src->width;
  height = src->height;

  /* duplicate malloc'd data */
  dest->format = src->format;
  dest->height = src->height;
  dest->width = src->width;

  switch (src->format) {
  case NONE:
    size = VL_NONE_SIZE (width, height);
    break;

  case RGB:
    size = VL_RGB_SIZE (width, height);
    break;

  case HSI:
    size = VL_HSI_SIZE (width, height);
    break;

  case GRAY:
    size = VL_GRAY_SIZE (width, height);
    break;

  case BINARY:
    size = VL_BINARY_SIZE (width, height);
    break;

  default:
	MessageBox(NULL,"unsupported image format\n","warnning",MB_OK);
    return (-1);		/* failure */
  }

  memcpy(dest->pixel, src->pixel, size);

  return (0);			/* success */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -