コード例 #1
0
ファイル: BinaryImage.cpp プロジェクト: FRC2404/year2014
/**
 * Get then number of particles for the image.
 * @returns the number of particles found for the image.
 */
int BinaryImage::GetNumberParticles()
{
	int numParticles = 0;
	int success = imaqCountParticles(m_imaqImage, 1, &numParticles);
	wpi_setImaqErrorWithContext(success, "Error counting particles");
	return numParticles;
}
コード例 #2
0
ファイル: BinaryImage.cpp プロジェクト: FRC2404/year2014
BinaryImage *BinaryImage::ConvexHull(bool connectivity8)
{
	BinaryImage *result = new BinaryImage();
	int success = imaqConvexHull(result->GetImaqImage(), m_imaqImage, connectivity8);
	wpi_setImaqErrorWithContext(success, "Error in convex hull operation");
	return result;
}
コード例 #3
0
ファイル: BinaryImage.cpp プロジェクト: FRC2404/year2014
/**
 * Measure a single parameter for an image.
 * Get the measurement for a single parameter about an image by calling the imaqMeasureParticle
 * function for the selected parameter.
 * @param particleNumber which particle in the set of particles
 * @param whatToMeasure the imaq MeasurementType (what to measure)
 * @param result the value of the measurement
 * @returns true on failure, false on success
 */
bool BinaryImage::ParticleMeasurement(int particleNumber, MeasurementType whatToMeasure, double *result)
{
	int success;
	success = imaqMeasureParticle(m_imaqImage, particleNumber, 0, whatToMeasure, result);
	wpi_setImaqErrorWithContext(success, "Error measuring particle");
	return !StatusIsFatal();
}
コード例 #4
0
ファイル: BinaryImage.cpp プロジェクト: FRC2404/year2014
BinaryImage *BinaryImage::RemoveLargeObjects(bool connectivity8, int erosions)
{
	BinaryImage *result = new BinaryImage();
	int success = imaqSizeFilter(result->GetImaqImage(), m_imaqImage, connectivity8, erosions, IMAQ_KEEP_SMALL, NULL);
	wpi_setImaqErrorWithContext(success, "Error in RemoveLargeObjects");
	return result;
}
コード例 #5
0
ファイル: ColorImage.cpp プロジェクト: PeterMitrano/allwpilib
// TODO: frcColorEqualize(Image* dest, const Image* source, int
// colorEqualization) needs to be modified
// The colorEqualization parameter is discarded and is set to TRUE in the call
// to imaqColorEqualize.
void ColorImage::Equalize(bool allPlanes) {
  // Note that this call uses NI-defined TRUE and FALSE
  int success = imaqColorEqualize(m_imaqImage,
                                  reinterpret_cast<const Image*>(m_imaqImage),
                                  (allPlanes) ? TRUE : FALSE);
  wpi_setImaqErrorWithContext(success, "Imaq ColorEqualize error");
}
コード例 #6
0
ファイル: BinaryImage.cpp プロジェクト: FRC2404/year2014
BinaryImage *BinaryImage::ParticleFilter(ParticleFilterCriteria2 *criteria, int criteriaCount)
{
	BinaryImage *result = new BinaryImage();
	int numParticles;
	ParticleFilterOptions2 filterOptions = {0, 0, 0, 1};
	int success = imaqParticleFilter4(result->GetImaqImage(), m_imaqImage, criteria, criteriaCount, &filterOptions, NULL, &numParticles);
	wpi_setImaqErrorWithContext(success, "Error in particle filter operation");
	return result;
}
コード例 #7
0
ファイル: ColorImage.cpp プロジェクト: 0xacf/wpilib
/**
 * Replace a plane in the ColorImage with a MonoImage
 * Replaces a single plane in the image with a MonoImage
 * @param mode The ColorMode in which to operate
 * @param plane The pointer to the replacement plane as a MonoImage
 * @param planeNumber The plane number (1, 2, 3) to replace
 */
void ColorImage::ReplacePlane(ColorMode mode, MonoImage *plane, int planeNumber) {
	int success = imaqReplaceColorPlanes(m_imaqImage, 
										 (const Image*) m_imaqImage, 
									     mode, 
									     (planeNumber == 1) ? plane->GetImaqImage() : NULL, 
									     (planeNumber == 2) ? plane->GetImaqImage() : NULL, 
									     (planeNumber == 3) ? plane->GetImaqImage() : NULL);
	wpi_setImaqErrorWithContext(success, "Imaq ReplaceColorPlanes failed");
}
コード例 #8
0
ファイル: ColorImage.cpp プロジェクト: PeterMitrano/allwpilib
/**
 * Replace a plane in the ColorImage with a MonoImage.
 *
 * Replaces a single plane in the image with a MonoImage.
 *
 * @param mode        The ColorMode in which to operate
 * @param plane       The pointer to the replacement plane as a MonoImage
 * @param planeNumber The plane number (1, 2, 3) to replace
 */
void ColorImage::ReplacePlane(ColorMode mode, MonoImage* plane,
                              int planeNumber) {
  int success = imaqReplaceColorPlanes(
      m_imaqImage, reinterpret_cast<const Image*>(m_imaqImage), mode,
      (planeNumber == 1) ? plane->GetImaqImage() : nullptr,
      (planeNumber == 2) ? plane->GetImaqImage() : nullptr,
      (planeNumber == 3) ? plane->GetImaqImage() : nullptr);
  wpi_setImaqErrorWithContext(success, "Imaq ReplaceColorPlanes failed");
}
コード例 #9
0
ファイル: ColorImage.cpp プロジェクト: frc1678/third-party
/**
 * Extract a color plane from the image.
 *
 * @param mode        The ColorMode to use for the plane extraction
 * @param planeNumber Which plane is to be extracted
 * @return A pointer to a MonoImage that represents the extracted plane.
 */
MonoImage* ColorImage::ExtractColorPlane(ColorMode mode, int planeNumber) {
  auto result = new MonoImage();
  if (m_imaqImage == nullptr) wpi_setWPIError(NullParameter);
  int success = imaqExtractColorPlanes(
      m_imaqImage, mode, (planeNumber == 1) ? result->GetImaqImage() : nullptr,
      (planeNumber == 2) ? result->GetImaqImage() : nullptr,
      (planeNumber == 3) ? result->GetImaqImage() : nullptr);
  wpi_setImaqErrorWithContext(success, "Imaq ExtractColorPlanes failed");
  return result;
}
コード例 #10
0
ファイル: ColorImage.cpp プロジェクト: frc1678/third-party
/**
 * Perform a threshold operation on a ColorImage.
 *
 * Perform a threshold operation on a ColorImage using the ColorMode supplied
 * as a parameter.
 *
 * @param colorMode The type of colorspace this operation should be performed in
 * @return a pointer to a binary image
 */
BinaryImage* ColorImage::ComputeThreshold(ColorMode colorMode, int low1,
                                          int high1, int low2, int high2,
                                          int low3, int high3) {
  auto result = new BinaryImage();
  Range range1 = {low1, high1}, range2 = {low2, high2}, range3 = {low3, high3};

  int success = imaqColorThreshold(result->GetImaqImage(), m_imaqImage, 1,
                                   colorMode, &range1, &range2, &range3);
  wpi_setImaqErrorWithContext(success, "ImaqThreshold error");
  return result;
}
コード例 #11
0
ファイル: BinaryImage.cpp プロジェクト: FRC2404/year2014
/**
 * Get a single particle analysis report.
 * Get one (of possibly many) particle analysis reports for an image.
 * This version could be more efficient when copying many reports.
 * @param particleNumber Which particle analysis report to return.
 * @param par the selected particle analysis report
 */
void BinaryImage::GetParticleAnalysisReport(int particleNumber, ParticleAnalysisReport *par)
{
	int success;
	int numParticles = 0;

	success = imaqGetImageSize(m_imaqImage, &par->imageWidth, &par->imageHeight);
	wpi_setImaqErrorWithContext(success, "Error getting image size");
	if (StatusIsFatal())
		return;

	success = imaqCountParticles(m_imaqImage, 1, &numParticles);
	wpi_setImaqErrorWithContext(success, "Error counting particles");
	if (StatusIsFatal())
		return;

	if (particleNumber >= numParticles)
	{
		wpi_setWPIErrorWithContext(ParameterOutOfRange, "particleNumber");
		return;
	}

	par->particleIndex = particleNumber;
	// Don't bother measuring the rest of the particle if one fails
	bool good = ParticleMeasurement(particleNumber, IMAQ_MT_CENTER_OF_MASS_X, &par->center_mass_x);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_CENTER_OF_MASS_Y, &par->center_mass_y);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA, &par->particleArea);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_TOP, &par->boundingRect.top);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_LEFT, &par->boundingRect.left);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_HEIGHT, &par->boundingRect.height);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_WIDTH, &par->boundingRect.width);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA_BY_IMAGE_AREA, &par->particleToImagePercent);
	good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA_BY_PARTICLE_AND_HOLES_AREA, &par->particleQuality);

	if (good)
	{
		/* normalized position (-1 to 1) */
		par->center_mass_x_normalized = NormalizeFromRange(par->center_mass_x, par->imageWidth);
		par->center_mass_y_normalized = NormalizeFromRange(par->center_mass_y, par->imageHeight);
	}
}
コード例 #12
0
ファイル: USBCamera.cpp プロジェクト: FRC3238/allwpilib
void USBCamera::OpenCamera() {
    std::lock_guard<priority_recursive_mutex> lock(m_mutex);
    for (unsigned int i = 0; i < 3; i++) {
        uInt32 id = 0;
        // Can't use SAFE_IMAQ_CALL here because we only error on the third time
        IMAQdxError error = IMAQdxOpenCamera(
                                m_name.c_str(), IMAQdxCameraControlModeController, &id);
        if (error != IMAQdxErrorSuccess) {
            // Only error on the 3rd try
            if (i >= 2) wpi_setImaqErrorWithContext(error, "IMAQdxOpenCamera");
            // Sleep for a few seconds to ensure the error has been dealt with
            std::this_thread::sleep_for(std::chrono::milliseconds(2000));
        } else {
            m_id = id;
            m_open = true;
            return;
        }
    }
}
コード例 #13
0
ファイル: RGBImage.cpp プロジェクト: PeterMitrano/allwpilib
/**
 * Create a new image by loading a file.
 *
 * @param fileName The path of the file to load.
 */
RGBImage::RGBImage(const char* fileName) : ColorImage(IMAQ_IMAGE_RGB) {
  int success = imaqReadFile(m_imaqImage, fileName, nullptr, nullptr);
  wpi_setImaqErrorWithContext(success, "Imaq ReadFile error");
}
コード例 #14
0
ファイル: ImageBase.cpp プロジェクト: FRCTeam1967/FRCTeam1967
/**
 * 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
 */
void ImageBase::Write(const char *fileName)
{
	int success = imaqWriteFile(m_imaqImage, fileName, NULL);
	wpi_setImaqErrorWithContext(success, "Imaq Image writeFile error");
}
コード例 #15
0
ファイル: HSLImage.cpp プロジェクト: anidev/frc-simulator
/**
 * Create a new image by loading a file.
 * @param fileName The path of the file to load.
 */
HSLImage::HSLImage(const char *fileName) : ColorImage(IMAQ_IMAGE_HSL)
{
    int success = imaqReadFile(m_imaqImage, fileName, NULL, NULL);
    wpi_setImaqErrorWithContext(success, "Imaq ReadFile error");
}