马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
初学halcon的同砚都知道:- read_image (Image, '1')
- get_image_size (Image, imgWidth, imgHeight)
- dev_open_window (0, 0,win_height, win_width, 'black', WindowHandle)
- *或者
- dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle1)
- *最后
- dev_set_part (0, 0, 511, 511)
- dev_display (Image)
复制代码 初学opencv的同砚也会知道:- import cv2
- image_path = 'image.jpg' # 图片路径
- image = cv2.imread(image_path)
- cv2.imshow('Image Window', image)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
复制代码 起首窗口尺寸是固定的(600*800)但是图像尺寸是厘革的,小到32*32大到5472*3648,以致更大。
这时halcon内里的dev_set_part有点用但是不会保持纵横比。
而opencv内里图像体现cv2.imshow是不能缩放的又乐意用matplotlib之类。
opencv体现大图就会特殊丢脸,信托实验过的同砚深有了解。
这时间halcon偶然候体现反而友爱一点。但是也不是很友爱。
偶然发现以下这么一行步调:
他可以支持恣意巨细的窗口打开恣意尺寸的图像并保持纵横比 固然 图像和图像框的比例不要相差过大。步调如下所示:作者已经不知道是谁了, 在此致敬先辈。 - HOperatorSet.GetImageSize(ho_image, out ImageWidth, out ImageHeight);
- HOperatorSet.SetPart(WindowID, 0, 0, ImageHeight, ImageWidth);
- HOperatorSet.DispObj(ho_image, WindowID);*/
- //获取图像及显示窗口长宽
- HOperatorSet.GetImageSize(image, out imgWidth, out imgHeight);
- int wndWidth = hSmartWindowControl1.ClientRectangle.Width;
- int wndHeight = hSmartWindowControl1.ClientRectangle.Height;
- //计算比例
- double scale = Math.Max(1.0 * imgWidth.I / wndWidth, 1.0 * imgHeight / wndHeight);
- double w = wndWidth * scale;
- double h = wndHeight * scale;
- //居中时,Part的区域
- hSmartWindowControl1.HalconWindow.SetPart(-(h - imgHeight) / 2, -(w - imgWidth) / 2, imgHeight + (h - imgHeight.D) / 2, imgWidth + (w - imgWidth) / 2);
- //背景色
- hSmartWindowControl1.HalconWindow.SetWindowParam("background_color", "black");
- hSmartWindowControl1.HalconWindow.ClearWindow();
- hSmartWindowControl1.HalconWindow.DispObj(image);
复制代码 由此我照葫芦画瓢做了halcon版本的:贴上去。- win_width:=500
- win_height:=500
- read_image (Image, '1')
- get_image_size (Image, imgWidth, imgHeight)
- scale:=max2(1.0 * imgWidth / win_width, 1.0 * imgHeight / win_height)
- w:=win_width*scale
- h:=win_height*scale
- dev_open_window (0, 0,win_height, win_width, 'black', WindowHandle)
- dev_set_part (-(h - imgHeight) / 2, -(w - imgWidth) / 2, imgHeight + (h - imgHeight) / 2, imgWidth + (w - imgWidth) / 2)
- dev_display (Image)
复制代码 公式没变语法不一样,只是。
接下来放大招:
python版本的halcon,经常逛CSDN的人都知道我是最早玩python版halcon的那一批人,python支持是早晚的事。
上步调:开始是如许画风。- Imagename="1rgb.bmp"
- #自适应窗口显示超大图和超小图
- win_width=500
- win_height=500
- imgWidth=5472
- imgHeight=3648
- #Image = ha.read_image(Imagename); Width, Height = ha.get_image_size(Image); imgWidth=Width[0]; imgHeight=Height[0] ;echo(f"{imgWidth}*{imgHeight}")
- scale=ha.tuple_max2(1.0 * imgWidth / win_width, 1.0 * imgHeight / win_height)
- w=win_width*scale[0]
- h=win_height*scale[0]
- WindowHandle =open_window(win_height, win_width,0,0,father_window=0)
- ha.set_part (WindowHandle,(-(h-imgHeight))/2, (-(w-imgWidth))/2, imgHeight+((h-imgHeight)/2), imgWidth+((w-imgWidth)/2))
- #ha.disp_obj(Image, WindowHandle);
- #img = cv2.imread(Imagename)#('1.bmp');
- #hacvimshow(img, WindowHandle)
复制代码 厥后:- def open_window(width, height,row=0,column=0,father_window=0):
- if os.name == 'nt':
- ha.set_system('use_window_thread', 'true')
- return ha.open_window(
- row=row,
- column=column,
- width=width,
- height=height,
- father_window=father_window,
- mode='visible',
- machine=''
- )
- def HaAutoSetPart(Image,WindowHandle,
- win_width=500,
- win_height=500,
- imgWidth=5472,
- imgHeight=3648
- ):
- #自适应窗口显示超大图和超小图
- scale=ha.tuple_max2(1.0 * imgWidth / win_width, 1.0 * imgHeight / win_height)
- w=win_width*scale[0]
- h=win_height*scale[0]
- ha.set_part (WindowHandle,
- (-(h-imgHeight))/2, (-(w-imgWidth))/2,
- imgHeight+((h-imgHeight)/2), imgWidth+((w-imgWidth)/2))
- ha.disp_obj(Image, WindowHandle);
- def hacvimshow(img, WindowHandle,ts=0.5):
- #img = img[:, :, ::-1]
- ha.disp_obj(ha.himage_from_numpy_array(img), WindowHandle);
- WindowHandle =open_window(win_height, win_width,0,0,father_window=0)
- HaAutoSetPart(img,WindowHandle1,
- win_width=Width,win_height=Height,
- #win_width=800,win_height=800,
- imgWidth=nWidth,imgHeight=nHeight)
- ha.disp_obj(img, WindowHandle1);
- hacvimshow(dilation, WindowHandle)#cv2.imshow("dilation",dilation)
复制代码 发现大招了不,在halcon内里可以
ha.disp_obj(img, WindowHandle1);
在opencv内里也可以用
hacvimshow(dilation, WindowHandle)#cv2.imshow("dilation",dilation)
以后调opencv多惬意。用hacvimshow(dilation, WindowHandle)
可以更换opencv 原来的 cv2.imshow("dilation",dilation) 窗口稳定的环境下自顺应很大大概很小的图 。 cv2.imshow 也不消resize了哈哈哈。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
|