CVI2012报错:Function imaqMorphology: (errorCode == -1074396154 [0xbff60406]). The image is not large e

问题

用 LabWindows CVI2012 做图像的形态学处理的时候,处理图像出现报错:

NON-FATAL RUN-TIME ERROR:   "morph_pro.c", line 88, col 9, thread id 0x00000C28:   
Function imaqMorphology: (errorCode == -1074396154 [0xbff60406]). The image is not large enough for the operation.

代码部分:

#include "nivision.h"
#include <cvirte.h>		
#include <userint.h>
#include "morph_pro.h"
#include "nivision.h"

static int morphMoth;
static Image *SourceImage;
static Image *DestImage;
static Image *TempImage; 

int main (int argc, char *argv[])
{
	if (InitCVIRTE (0, argv, 0) == 0)
		return -1;	/* out of memory */
	if ((morphMoth = LoadPanel (0, "morph_pro.uir", MORPH_MOTH)) < 0)
		return -1;
	DisplayPanel (morphMoth);
	SourceImage = imaqCreateImage(IMAQ_IMAGE_U8, 2);
	DestImage = imaqCreateImage(IMAQ_IMAGE_U8, 2);
	TempImage = imaqCreateImage(IMAQ_IMAGE_U8, 2);   
	RunUserInterface ();
	DiscardPanel (morphMoth);
	return 0;
}

int CVICALLBACK Load_image(int panel, int control, int event,
	void *callbackData, int eventData1, int eventData2)
{
	char fileName[512];
	int status;
	HistogramReport *report;  
	switch (event)
	{
	case EVENT_COMMIT:
			status = FileSelectPopup("", "*.bmp*", "", "select an image file", VAL_LOAD_BUTTON, 0, 0, 1, 0, fileName);
	if (status == 1)
	{
		imaqReadFile(SourceImage, fileName, NULL, NULL);
		imaqMoveWindow(0, imaqMakePoint(50, 260));
		imaqDisplayImage(SourceImage, 0, TRUE);
		report = imaqHistogram(SourceImage, 256, 0, 255,
				IMAQ_IMAGE_U8);
		DeleteGraphPlot(morphMoth, MORPH_MOTH_HISTOGRAM, -1, VAL_IMMEDIATE_DRAW);
		PlotY(morphMoth, MORPH_MOTH_HISTOGRAM,
				(*report).histogram, 256,
				VAL_UNSIGNED_INTEGER, VAL_THIN_LINE,
				VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
	}
		break;
	}
	return 0;
}

int CVICALLBACK Threshold(int panel, int control, int event,
	void *callbackData, int eventData1, int eventData2)
{
	int thre_value;
	HistogramReport *report; 
	switch (event)
	{
	case EVENT_COMMIT:
		GetCtrlVal(morphMoth, MORPH_MOTH_NUMERICSLIDE, &thre_value);
		imaqThreshold(DestImage, SourceImage, thre_value, 255,
			TRUE, 255);
		imaqSetWindowTitle(1, "二值化分割");
		imaqMoveWindow(1, imaqMakePoint(150, 260));
		imaqDisplayImage(DestImage, 1, TRUE);
		report = imaqHistogram(DestImage, 256, 0, 255, IMAQ_IMAGE_U8);
		DeleteGraphPlot(morphMoth, MORPH_MOTH_HISTOGRAM,
			-1, VAL_IMMEDIATE_DRAW);
		PlotY(morphMoth, MORPH_MOTH_HISTOGRAM, (*report).histogram,
			256, VAL_UNSIGNED_INTEGER, VAL_THIN_LINE, VAL_EMPTY_SQUARE,
			VAL_SOLID, 1, VAL_RED);
		break;
	}
	return 0;
}

int CVICALLBACK Morph_processing(int panel, int control, int event,
	void *callbackData, int eventData1, int eventData2)
{
	int methodValue;
	switch (event)
	{
	case EVENT_COMMIT:
		GetCtrlVal(morphMoth, MORPH_MOTH_MORPH_MOTHED, &methodValue);
		imaqMorphology(DestImage, TempImage, methodValue, NULL);  
		imaqSetWindowPalette(2, IMAQ_PALETTE_BINARY, NULL, 2);
		imaqSetWindowTitle(2, "形态学处理");
		imaqMoveWindow(2, imaqMakePoint(50, 60));
		imaqDisplayImage(DestImage, 2, TRUE);    
		imaqDisplayImage(TempImage, 2, TRUE);  
		break;
	}
	return 0;
}

int CVICALLBACK Save_an_image(int panel, int control, int event,
	void *callbackData, int eventData1, int eventData2)
{
	char SavePath[260];
	ImageInfo Image_Info;
	int status;
	int width, height;
	switch (event)
	{
	case EVENT_COMMIT:
		status = FileSelectPopup("", "*.bmp,*.tif,*.apd", "*.bmp", 
			"Select a SavePath", VAL_SAVE_BUTTON, 0, 0, 1, 0, SavePath);
		if (status)
		{
			imaqWriteFile(DestImage, SavePath, NULL);
		}
		break;
	}
	return 0;
}

int CVICALLBACK Quit (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	switch (event)
	{
		case EVENT_COMMIT:
			QuitUserInterface (0);
			break;
	}
	return 0;
}

原因

TempImage 和 DestImage 尺寸大小不一

解决

在形态学处理之前,利用 imaqSetImageSize () 函数将两张图像缩放到同一尺寸

		imaqSetImageSize(TempImage,640,320);    
		imaqSetImageSize(DestImage,640,320);

完整代码:

#include "nivision.h"
#include <cvirte.h>		
#include <userint.h>
#include "morph_pro.h"
#include "nivision.h"

static int morphMoth;
static Image *SourceImage;
static Image *DestImage;
static Image *TempImage; 

int main (int argc, char *argv[])
{
	if (InitCVIRTE (0, argv, 0) == 0)
		return -1;	/* out of memory */
	if ((morphMoth = LoadPanel (0, "morph_pro.uir", MORPH_MOTH)) < 0)
		return -1;
	DisplayPanel (morphMoth);
	SourceImage = imaqCreateImage(IMAQ_IMAGE_U8, 2);
	DestImage = imaqCreateImage(IMAQ_IMAGE_U8, 2);
	TempImage = imaqCreateImage(IMAQ_IMAGE_U8, 2);   
	RunUserInterface ();
	DiscardPanel (morphMoth);
	return 0;
}

int CVICALLBACK Load_image(int panel, int control, int event,
	void *callbackData, int eventData1, int eventData2)
{
	char fileName[512];
	int status;
	HistogramReport *report;  
	switch (event)
	{
	case EVENT_COMMIT:
			status = FileSelectPopup("", "*.bmp*", "", "select an image file", VAL_LOAD_BUTTON, 0, 0, 1, 0, fileName);
	if (status == 1)
	{
		imaqReadFile(SourceImage, fileName, NULL, NULL);
		imaqMoveWindow(0, imaqMakePoint(50, 260));
		imaqDisplayImage(SourceImage, 0, TRUE);
		report = imaqHistogram(SourceImage, 256, 0, 255,
				IMAQ_IMAGE_U8);
		DeleteGraphPlot(morphMoth, MORPH_MOTH_HISTOGRAM, -1, VAL_IMMEDIATE_DRAW);
		PlotY(morphMoth, MORPH_MOTH_HISTOGRAM,
				(*report).histogram, 256,
				VAL_UNSIGNED_INTEGER, VAL_THIN_LINE,
				VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
	}
		break;
	}
	return 0;
}

int CVICALLBACK Threshold(int panel, int control, int event,
	void *callbackData, int eventData1, int eventData2)
{
	int thre_value;
	HistogramReport *report; 
	switch (event)
	{
	case EVENT_COMMIT:
		imaqSetImageSize(TempImage,640,320);    
		imaqSetImageSize(DestImage,640,320);
		GetCtrlVal(morphMoth, MORPH_MOTH_NUMERICSLIDE, &thre_value);
		imaqThreshold(DestImage, SourceImage, thre_value, 255,
			TRUE, 255);
		imaqSetWindowTitle(1, "二值化分割");
		imaqMoveWindow(1, imaqMakePoint(150, 260));
		imaqDisplayImage(DestImage, 1, TRUE);
		report = imaqHistogram(DestImage, 256, 0, 255, IMAQ_IMAGE_U8);
		DeleteGraphPlot(morphMoth, MORPH_MOTH_HISTOGRAM,
			-1, VAL_IMMEDIATE_DRAW);
		PlotY(morphMoth, MORPH_MOTH_HISTOGRAM, (*report).histogram,
			256, VAL_UNSIGNED_INTEGER, VAL_THIN_LINE, VAL_EMPTY_SQUARE,
			VAL_SOLID, 1, VAL_RED);
		break;
	}
	return 0;
}

int CVICALLBACK Morph_processing(int panel, int control, int event,
	void *callbackData, int eventData1, int eventData2)
{
	int methodValue;
	switch (event)
	{
	case EVENT_COMMIT:
		GetCtrlVal(morphMoth, MORPH_MOTH_MORPH_MOTHED, &methodValue);
		imaqMorphology(DestImage, TempImage, methodValue, NULL);  
		imaqSetWindowPalette(2, IMAQ_PALETTE_BINARY, NULL, 2);
		imaqSetWindowTitle(2, "形态学处理");
		imaqMoveWindow(2, imaqMakePoint(50, 60));
		imaqDisplayImage(DestImage, 2, TRUE);    
		imaqDisplayImage(TempImage, 2, TRUE);  
		break;
	}
	return 0;
}

int CVICALLBACK Save_an_image(int panel, int control, int event,
	void *callbackData, int eventData1, int eventData2)
{
	char SavePath[260];
	ImageInfo Image_Info;
	int status;
	int width, height;
	switch (event)
	{
	case EVENT_COMMIT:
		status = FileSelectPopup("", "*.bmp,*.tif,*.apd", "*.bmp", 
			"Select a SavePath", VAL_SAVE_BUTTON, 0, 0, 1, 0, SavePath);
		if (status)
		{
			imaqWriteFile(DestImage, SavePath, NULL);
		}
		break;
	}
	return 0;
}

int CVICALLBACK Quit (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	switch (event)
	{
		case EVENT_COMMIT:
			QuitUserInterface (0);
			break;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不雨_亦潇潇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值