2014-12-23 15:55:36 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
|
2014-12-23 15:55:36 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2014-12-23 15:55:36 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "Vision/ImageBase.h"
|
|
|
|
|
#include "nivision.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new instance of an ImageBase.
|
|
|
|
|
* Imagebase is the base of all the other image classes. The constructor
|
|
|
|
|
* creates any type of image and stores the pointer to it in the class.
|
|
|
|
|
* @param type The type of image to create
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
ImageBase::ImageBase(ImageType type) {
|
|
|
|
|
m_imaqImage = imaqCreateImage(type, DEFAULT_BORDER_SIZE);
|
2014-12-23 15:55:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Frees memory associated with an ImageBase.
|
|
|
|
|
* Destructor frees the imaq image allocated with the class.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
ImageBase::~ImageBase() {
|
|
|
|
|
if (m_imaqImage) imaqDispose(m_imaqImage);
|
2014-12-23 15:55:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Writes an image to a file with the given filename.
|
|
|
|
|
* Write the image to a file in the flash on the cRIO.
|
|
|
|
|
* @param fileName The name of the file to write
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void ImageBase::Write(const char *fileName) {
|
2015-06-23 04:49:51 -07:00
|
|
|
int success = imaqWriteFile(m_imaqImage, fileName, nullptr);
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setImaqErrorWithContext(success, "Imaq Image writeFile error");
|
2014-12-23 15:55:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the height of an image.
|
|
|
|
|
* @return The height of the image in pixels.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
int ImageBase::GetHeight() {
|
|
|
|
|
int height;
|
2015-06-23 04:49:51 -07:00
|
|
|
imaqGetImageSize(m_imaqImage, nullptr, &height);
|
2015-06-25 15:07:55 -04:00
|
|
|
return height;
|
2014-12-23 15:55:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the width of an image.
|
|
|
|
|
* @return The width of the image in pixels.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
int ImageBase::GetWidth() {
|
|
|
|
|
int width;
|
2015-06-23 04:49:51 -07:00
|
|
|
imaqGetImageSize(m_imaqImage, &width, nullptr);
|
2015-06-25 15:07:55 -04:00
|
|
|
return width;
|
2014-12-23 15:55:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Access the internal IMAQ Image data structure.
|
2015-06-25 15:07:55 -04:00
|
|
|
*
|
2014-12-23 15:55:36 -05:00
|
|
|
* @return A pointer to the internal IMAQ Image data structure.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
Image *ImageBase::GetImaqImage() { return m_imaqImage; }
|