大恒水星相机开发记录

您所在的位置:网站首页 featureone软件教程采集在哪里 大恒水星相机开发记录

大恒水星相机开发记录

2023-12-23 04:21| 来源: 网络整理| 查看: 265

大恒水星相机开发记录

前面的话: 最近搞了一个大恒的相机MER-500-14GC,本着这可是行业龙头的工业相机嘛,终归是在学校摸到了真正的工业级产品了。(٩(๑>◡properties弹出Property page窗口。 选择Configuration Properties->C/C++ ->General在Additional Include Directories中填写GalaxyIncludes.h所在目录路径地址(依用户安装目录为准)。我的GalaxyIncludes.h路径是:G:\GalaxySDK\Samples\C++ SDK\inc。环境是X64的环境,记着那个opencv的环境也是X64,最后编译环境也是X64 在这里插入图片描述

配置lib文件 然后选择Configuration Properties->Linker->General在Additional Library Directories中填写GxIAPICPPEx.lib所在目录路径地址(依用户安装目录为准)。我的是:G:\GalaxySDK\Samples\C++ SDK\lib\x64 在这里插入图片描述

然后选择Configuration Properties->Linker->Input在Additional Dependencies中填写GxIAPICPPEx.lib,并不像图中这样啊

在这里插入图片描述

VS(c++)中调用相机 首先先说官方文档提供的例程:

在这里插入图片描述

这个例程在改了一些代码中各种的小错后,我始终是运行不起来,总是报错,错误代码-8,如下 在这里插入图片描述 阿西吧,为啥啊??趟坑路上处处是雷Σ_(꒪ཀ꒪」∠)

大佬的代码

这里的原文参考自这里:感谢这位大佬拯救了我

首先在这个路径G:\GalaxySDK\Samples\C++ SDK\inc下的gxsmartptr.h中添加一行#include "GalaxyException.h"然后上代码 #include #include #include "GalaxyException.h" //using namespace cv; using namespace std; #include cv::Mat img; //用户继承掉线事件处理类 class CSampleDeviceOfflineEventHandler : public IDeviceOfflineEventHandler { public: void DoOnDeviceOfflineEvent(void* pUserParam) { cout cout cout do { //枚举设备 gxdeviceinfo_vector vectorDeviceInfo; IGXFactory::GetInstance().UpdateDeviceList(1000, vectorDeviceInfo); if (0 == vectorDeviceInfo.size()) { cout StartGrab(); ObjFeatureControlPtr->GetCommandFeature("AcquisitionStart")->Execute(); //此时开采成功,控制台打印信息,直到输入任意键继续 getchar(); //发送停采命令 ObjFeatureControlPtr->GetCommandFeature("AcquisitionStop")->Execute(); ObjStreamPtr->StopGrab(); //注销采集回调 ObjStreamPtr->UnregisterCaptureCallback(); //注销远端设备事件 //ObjFeatureControlPtr->UnregisterFeatureCallback(hFeatureEvent); //注销设备掉线事件 //ObjDevicePtr->UnregisterDeviceOfflineCallback(hDeviceOffline); //释放资源 ObjStreamPtr->Close(); ObjDevicePtr->Close(); } while (0); } catch (CGalaxyException& e) { cout delete pCaptureEventHandler; pCaptureEventHandler = NULL; } if (NULL != pDeviceOfflineEventHandler) { delete pDeviceOfflineEventHandler; pDeviceOfflineEventHandler = NULL; } if (NULL != pFeatureEventHandler) { delete pFeatureEventHandler; pFeatureEventHandler = NULL; } return 0; }

这里我出现了两个结果

成功执行,显示图像和图像信息在这里插入图片描述 在这里插入图片描述

失败,错误代码-8 。。。阿西吧,这里我找了半天错,就是那种同样的代码咋关掉再打开就报错啦??后来发现可能是 在这里插入图片描述 也许是这个问题吧,解决方法嘛就果断重启相机试试,哦吼,成了。。。这里之后再看看咋改吧,目前先这样。

windows(python)

比起c++我python更熟悉一些,于是乎又去看了看pyhton的接口 G:\GalaxySDK\Samples\Python SDK这个文件夹中写好了官方给的接口,哦吼吼,这个接口真不错,比C++那个靠谱多了 在这里插入图片描述 我相机彩色的于是乎选了那个color的,完美运行 在这里插入图片描述

这个大概需要一些。。。opencv啊PIL啊numpy啊大概的包吧,这些我都有了就不讲咋安了,都是conda install 或者pip 嘛。 官方提供的那个readme我没用那种安装方法,conda多好,环境这里就不讲了。

OK我们来看看代码,嗯嗯嗯。。。官方接口都给到numpy了,最后用的PIL显示,这不就简单了嘛,分分钟改成opencv的Mat格式。

import gxipy as gx from PIL import Image import cv2 def main(): # print the demo information print("") print("-------------------------------------------------------------") print("Sample to show how to acquire color image continuously and show acquired image.") print("-------------------------------------------------------------") print("") print("Initializing......") print("") # create a device manager device_manager = gx.DeviceManager() dev_num, dev_info_list = device_manager.update_device_list() if dev_num == 0: print("Number of enumerated devices is 0") return # open the first device cam = device_manager.open_device_by_index(1) # exit when the camera is a mono camera if cam.PixelColorFilter.is_implemented() is False: print("This sample does not support mono camera.") cam.close_device() return # set continuous acquisition cam.TriggerMode.set(gx.GxSwitchEntry.OFF) # set exposure cam.ExposureTime.set(10000.0) # set gain cam.Gain.set(10.0) # get param of improving image quality if cam.GammaParam.is_readable(): gamma_value = cam.GammaParam.get() gamma_lut = gx.Utility.get_gamma_lut(gamma_value) else: gamma_lut = None if cam.ContrastParam.is_readable(): contrast_value = cam.ContrastParam.get() contrast_lut = gx.Utility.get_contrast_lut(contrast_value) else: contrast_lut = None if cam.ColorCorrectionParam.is_readable(): color_correction_param = cam.ColorCorrectionParam.get() else: color_correction_param = 0 # start data acquisition cam.stream_on() # acquisition image: num is the image number num = 1 for i in range(num): # get raw image raw_image = cam.data_stream[0].get_image() if raw_image is None: print("Getting image failed.") continue # get RGB image from raw image rgb_image = raw_image.convert("RGB") if rgb_image is None: continue # improve image quality rgb_image.image_improvement(color_correction_param, contrast_lut, gamma_lut) # create numpy array with data from raw image numpy_image = rgb_image.get_numpy_array() if numpy_image is None: continue # show acquired image # 这里改用opencv显示 cv_img = cv2.cvtColor(numpy_image, cv2.COLOR_BGR2RGB) cv2.imshow("opencv", cv_img) cv2.waitKey(0) cv2.destroyAllWindows() # 这里用PIL显示 img = Image.fromarray(numpy_image, 'RGB') img.show() # print height, width, and frame ID of the acquisition image print("Frame ID: %d Height: %d Width: %d" % (raw_image.get_frame_id(), raw_image.get_height(), raw_image.get_width())) # stop data acquisition cam.stream_off() # close device cam.close_device() if __name__ == "__main__": main()

还是python简单啊,唉,要不是行业里都是C++部署,python多好用啊,唉。

相机的内部设定

照出来的图像各种参数,颜色,饱和度,伽马值,亮度啥的这些其实是用官方文档里写的接口去调的,调好了直接写在相机内部,这里由于本博主太菜,且发现用demo也能调,所以嘛就不费事了。 下载的资料中,官方提供了一个工具demo,GalaxyView.exe,这个咋用官方文档里写的清清楚楚,我只讲一下用这个设置相机,这里如图: 在这里插入图片描述

把插件下面第2,3,4全打开

在这里插入图片描述 可以看到这里可以进行各种设定,原理这里我也不是很懂,之前我都是采集上来用opencv或者imaug去调的,而像这种工业相机应该是要用自己的库,所以这种调整处理是大恒官方写的,文档里有方法,这里就不深究了。 这里调好了就写入到设备里,这样就OK了。

ubuntu系统 c++接口

这里在官网下载指定的SDK

根据readme安装,这里会在环境变量中添加几个路径,所以安装完了不能改路径

安装完成后进入看bin目录下的GalaxyView和GxGigeIPConfig和windows下的一样设置一下ip

重点:我是直接网口连的电脑主板,在上一步发现读取不到图像信息。询问技术客服后解决

方法:设置网口的mtu 设置网络设备的MTU 在这里插入图片描述之前是1500,现在设置成8192 在这里插入图片描述这里也要设置成8192(默认就是,但是还是要看一眼) 在这里插入图片描述

OK,这样运行提供的例子就没问题了

python接口

这里下载的linux文件没有提供python接口 其实直接把windows提供的python—SDK拿过来用就行了



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3