CVI2012报错:Function imaqReadFile: (errorCode == -1074396120 [0xbff60428]). Not an image.问题解决

问题

用 LabWindows CVI2012 做直方图均衡化的时候,读入图像出现报错:

NON-FATAL RUN-TIME ERROR:   "his.c", line 33, col 17, thread id 0x00004240:
Function imaqReadFile: (errorCode == -1074396120 [0xbff60428]). Not an image.

代码部分:

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

static int panelHandle;
static Image *SourceImage;

int main (int argc, char *argv[])
{
	if (InitCVIRTE (0, argv, 0) == 0)
		return -1;	/* out of memory */
	if ((panelHandle = LoadPanel (0, "his.uir", PANEL)) < 0)
		return -1;
	DisplayPanel (panelHandle);
	RunUserInterface ();
	DiscardPanel (panelHandle);
	return 0;
}

int CVICALLBACK Load_and_display(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(panelHandle, PANEL_HISTOGRAM, -1,
					VAL_IMMEDIATE_DRAW);
				PlotY(panelHandle, PANEL_HISTOGRAM, (*report).histogram,
					256, VAL_UNSIGNED_INTEGER, VAL_THIN_LINE,
					VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
			}
		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;
}

运行的时候面板能够打开,从目录中选取读入的图像文件也没有问题,但在点击 Load 加载图像的时候就遇到了报错。

刚开始看到 Not an image 我以为是图像有问题,把原本读入的 jpg 文件换成 bmp 文件,后来发现还是行不通

原因

代码中虽然定义了 SourceImage ,但是没有创建存储区域

解决

在 main() 函数中添加代码:

SourceImage = imaqCreateImage (IMAQ_IMAGE_U8, 2);   

完整代码:

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

static int panelHandle;
static Image *SourceImage;

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

int CVICALLBACK Load_and_display(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(panelHandle, PANEL_HISTOGRAM, -1,
					VAL_IMMEDIATE_DRAW);
				PlotY(panelHandle, PANEL_HISTOGRAM, (*report).histogram,
					256, VAL_UNSIGNED_INTEGER, VAL_THIN_LINE,
					VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
			}
		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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

不雨_亦潇潇

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

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

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

打赏作者

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

抵扣说明:

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

余额充值