普通图像数据转换为halcon能操作的图像数据的办法
By
admin
at 2019-05-11 • 1人收藏 • 2397人看过
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=1171;bottom=767) winform.add( picturebox={cls="picturebox";left=400;top=0;right=1172;bottom=768;z=1}; picturebox2={cls="picturebox";left=0;top=0;right=317;bottom=267;z=2} ) /*}}*/ import soImage; HOperatorSetX = com.CreateObject("{6ebd90e2-d219-11d2-ade5-0000c00f4ef9}") /* Image = HOperatorSetX.ReadImage( 'C:/Users/popdes/Desktop/f083.png' ); var GrayImage = HOperatorSetX.Rgb1ToGray( Image ); var Width , Height = HOperatorSetX.GetImageSize( GrayImage ); */ var simg = soImage(); simg.load("C:\Users\popdes\Desktop\f083.png") simg.grayScale(); winform.picturebox2.image = simg.getBytes("*.bmp") //垂直翻转, 不执行这个会导致图像上下反的 simg.flip() var addr = tonumber(raw.toPointer(simg.getBytes("*.bmp"))); var Image = HOperatorSetX.GenImage1( "byte" , simg.getWidth() , simg.getHeight() , addr ); var WindowHandle = HOperatorSetX.OpenWindow( 0 , 0 , winform.picturebox.width , winform.picturebox.height , winform.picturebox.hwnd , "visible", "" ); HOperatorSetX.DispObj( Image , WindowHandle ); winform.show(); win.loopMessage(); return winform;
先记录到这里, 明显是有问题的, 正常情况下, 窗口应该两个图像显示的一致, 但是这个显示明显左右分离了
2 个回复 | 最后更新于 2019-05-12
halcon图像变量转普通bitmap图像
代码如下,目前还有问题, 没实现成功, 以后有时间继续研究, 先放一边
var PointerRed , PointerGreen , PointerBlue , Type , Width , Height = HOperatorSetX.GetImagePointer3( Image ); console.varDump(PointerRed) var PRed = raw.buffer(raw.tostring(topointer(PointerRed))) var PGreen = raw.buffer(raw.tostring(topointer(PointerGreen))) var PBlue= raw.buffer(raw.tostring(topointer(PointerBlue))) console.log(Type , Width , Height) var bmp5 = gdip.bitmap(Height , Width); //获取位图数据 var bmpdata = bmp5.lockData32(,0x22009/*_PixelFormat32bppRGB*/); var bptr = bmpdata.Scan0; for(i=1;Width*Height;1){ bptr[(i-1)*4+1]=PBlue[i]; bptr[(i-1)*4+2]=PGreen[i]; bptr[(i-1)*4+3]=PRed[i]; bptr[(i-1)*4+4]=255; } bmp5.unlockData(bmpdata); winform.plus.background = bmp5;
目前还只是黑色一片.......
登录后方可回帖
上面实现的方式有点问题, 去网上搜了下
参考网址里面的写法https://blog.csdn.net/bingbingxie1/article/details/83344704
实现了 bitmap变量转为 halcon变量