| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631 |
- using OpenCvSharp;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.Data.Param;
- using PaintDotNet.DedicatedAnalysis.GrainSize.GBT6394_2017;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Windows.Forms;
- using Point = System.Drawing.Point;
- using PaintDotNet.Base.Functionodel;
- using PaintDotNet.Base.Enum;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.CustomControl;
- using PaintDotNet.Adjust.BaseImage;
- using Application = System.Windows.Forms.Application;
- using GroupBox = System.Windows.Forms.GroupBox;
- using CheckBox = System.Windows.Forms.CheckBox;
- using Button = System.Windows.Forms.Button;
- using Label = System.Windows.Forms.Label;
- using ListBox = System.Windows.Forms.ListBox;
- using TextBox = System.Windows.Forms.TextBox;
- using System.Data;
- using PaintDotNet.Base;
- using PaintDotNet.DbOpreate.DbModel;
- namespace PaintDotNet.DedicatedAnalysis.GrainSize
- {
- internal class GrainSizeBoundryEditDialog : PdnBaseForm
- {
- /// <summary>
- /// 晶粒度(面积法)
- /// </summary>
- #region 控件
- private GroupBox groupBox1;
- private Button button2;
- private CheckBox checkBox2_0;
- private GroupBox groupBox2;
- private ListView listView1;
- private Button button9;
- private GroupBox groupBox8;
- private NumericUpDown numericUpDown1_0;
- private Button button16;
- private Label label5;
- private Button button14;
- private Button button13;
- private DataGridView dataGridView4;
- private Button button12;
- private Button button11;
- private Label label4;
- private Label label3;
- private GroupBox groupBox7;
- private GroupBox groupBox3;
- private GroupBox groupBox11;
- private ComboBox comboBox1;
- private CheckBox checkBox5_0;
- private CheckBox checkBox4_0;
- private CheckBox checkBox3_0;
- private ImageList imageList1;
- private IContainer components;
- private Button button1;
- #endregion
- /// <summary>
- /// 主控件
- /// </summary>
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 0,GBT6394; ; 2,GBT24177; 3,E112; 4,ISO643
- /// </summary>
- int gbtType;
- /// <summary>
- /// 用于编号的坐标点集合
- /// </summary>
- List<Point2d> massLabelPoints = new List<Point2d>();
- //分析结果列表的头标题
- /// <summary>
- /// "图片", "网格", "网格面积", "晶粒数", "平均晶粒度级别"
- /// </summary>
- List<string> contentHead = new List<string>() { "图片", "网格", "网格面积", "晶粒数", "平均晶粒度级别" };
- /// <summary>
- /// 保存用于生成报告的图片
- /// </summary>
- private List<Bitmap> bitList;
- /// <summary>
- /// 储存点击保存结果后的所有原图与分析图
- /// </summary>
- private Dictionary<string, List<Bitmap>> bitDic = new Dictionary<string, List<Bitmap>>();
- #region 二值化相关
- /// <summary>
- /// 初始系统参数配置值
- /// </summary>
- private BinaryExtractionModel binaryExtractionModel;
- /// <summary>
- /// 处理程序
- /// </summary>
- private ParamObject action = new Data.Action.Action901();
- /// <summary>
- /// 调色板
- /// </summary>
- private ColorsForm colorsFormGrid;
- /// <summary>
- /// 当前点击调色板
- /// </summary>
- private int currentPanel = 1;
- /// <summary>
- /// 参数下拉的集合
- /// </summary>
- private List<string> files = new List<string>();
- #endregion
- /// <summary>
- /// 选中图片的bitmap
- /// </summary>
- private Bitmap bitmap;
- private DocumentWorkspaceWindow documentWorkspace;
- /// <summary>
- /// 公共按钮
- /// </summary>
- private CommonControlButtons commonControlButtons;
- #region 截点样式
- /// <summary>
- /// 颜色(0.5)
- /// </summary>
- private int pointColor1;
- /// <summary>
- /// 线宽(0.5)
- /// </summary>
- private int pointWidth1;
- /// <summary>
- /// 点样式 0:空心 1:实心(0.5)
- /// </summary>
- private int pointStyle1;
- /// <summary>
- /// 大小(0.5)
- /// </summary>
- private int pointDiameter1;
- /// <summary>
- /// 截点误差(0.5)
- /// </summary>
- private int pointError1;
- /// <summary>
- /// 形状 0:圆形 1:方形(0.5)
- /// </summary>
- private int pointshape1;
- /// <summary>
- /// 颜色(1)
- /// </summary>
- private int pointColor2;
- /// <summary>
- /// 线宽(1)
- /// </summary>
- private int pointWidth2;
- /// <summary>
- /// 点样式 0:空心 1:实心(1)
- /// </summary>
- private int pointStyle2;
- /// <summary>
- /// 大小(1)
- /// </summary>
- private int pointDiameter2;
- /// <summary>
- /// 截点误差(1)
- /// </summary>
- private int pointError2;
- /// <summary>
- /// 形状 0:圆形 1:方形(1)
- /// </summary>
- private int pointshape2;
- /// <summary>
- /// 颜色(1.5/2)
- /// </summary>
- private int pointColor3;
- /// <summary>
- /// 线宽(1.5/2)
- /// </summary>
- private int pointWidth3;
- /// <summary>
- /// 点样式 0:空心 1:实心(1.5/2)
- /// </summary>
- private int pointStyle3;
- /// <summary>
- /// 大小(1.5/2)
- /// </summary>
- private int pointDiameter3;
- /// <summary>
- /// 截点误差(1.5/2)
- /// </summary>
- private int pointError3;
- /// <summary>
- /// 形状 0:圆形 1:方形(1.5/2)
- /// </summary>
- private int pointshape3;
- #endregion
- #region 辅助线样式
- /// <summary>
- /// 矩形宽
- /// </summary>
- public int lineRectangleWidth;
- /// <summary>
- /// 矩形高
- /// </summary>
- public int lineRectangleHeight;
- /// <summary>
- /// 直径
- /// </summary>
- public int lineDiameter;
- /// <summary>
- /// 线颜色
- /// </summary>
- public int lineColor;
- /// <summary>
- /// 线宽
- /// </summary>
- public int lineWidth;
- #endregion
- GrainCutOffPointStyleModel grainCutOffPointStyleModel;
- GrainSizeGuideAreaMethodModel grainSizeGuideAreaMethodModel;
- /// <summary>
- /// 是否选择了图片
- /// </summary>
- private bool selectPicture = false;
- /// <summary>
- /// 存在视场标记
- /// </summary>
- private bool existViewFlag = false;
- /// <summary>
- /// 当前选择的图片
- /// </summary>
- private Mat mat;
- /// <summary>
- /// 鼠标移动最后一次的坐标,换算后的
- /// </summary>
- private int x, y;
- /// <summary>
- /// 最后一次坐标,换算前的
- /// </summary>
- private int ox, oy;
- /// <summary>
- /// 容许值
- /// </summary>
- private int tolerance = 0;
- /// <summary>
- /// 循环时用来计算的
- /// </summary>
- private byte maxB = 0, maxG = 0, maxR = 0;
- /// <summary>
- /// 循环时用来计算的
- /// </summary>
- private byte minB = 255, minG = 255, minR = 255;
- /// <summary>
- /// 传递给计算函数的坐标
- /// </summary>
- private int xn, yn;
- /// <summary>
- /// 鼠标点击标记
- /// </summary>
- private bool mouseClick = false;
- /// <summary>
- /// 用于标记是撤销重做,以免再次加入集合
- /// </summary>
- private bool doOrRedo = false;
- /// <summary>
- /// 第一次双击的标记
- /// </summary>
- private bool firstFlag = false;
- private Mat mat1;
- /// <summary>
- /// 当前相model
- /// </summary>
- private PhaseModel model;
- /// <summary>
- /// 用于撤销恢复
- /// </summary>
- private List<MultiPhaseStepModel> steps = new List<MultiPhaseStepModel>();
- /// <summary>
- /// 用于记录当前的撤销恢复步骤
- /// </summary>
- private int currentPosition = -1;
- /// <summary>
- /// RGB/HLS 选中那个按钮,默认1=R/H 2=G/L 2=B/S
- /// </summary>
- private int HistogramRGBSelect = 1;
- /// <summary>
- /// 当前使用轮廓的形状
- /// </summary>
- private ContourParameters contourParameters;
- /// <summary>
- /// 多边形的点集合
- /// </summary>
- private List<PointF> points;
- /// <summary>
- /// 矩形或椭圆的外接矩形
- /// </summary>
- private RectangleF rectangleFOut;
- /// <summary>
- /// 截点矩形集合
- /// </summary>
- private List<RectangleF> rectangleFCaps = new List<RectangleF>();
- /// <summary>
- /// 节点区分 1:0.5截点 | 2:1截点 | 3:1.5/2截点
- /// </summary>
- private int pointKb = 0;
- /// <summary>
- /// 是否二值化
- /// </summary>
- private bool binarization = true;
- /// <summary>
- /// 分析结果暂存
- /// </summary>
- private List<System.Data.DataTable> dataTables = new List<System.Data.DataTable>();
- /// <summary>
- /// 全部显示
- /// </summary>
- private bool allShow = false;
- /// <summary>
- /// 图形位置
- /// </summary>
- private PointF loctation;
- /// <summary>
- /// 图形上所有的点
- /// </summary>
- private List<PointF> linePointList = new List<PointF>();
- /// <summary>
- /// 小数
- /// </summary>
- private int dec;
- private int oldSelectIndex;
- private PointF m_StartPoint = Point.Empty;
- private bool m_canMove;
- private RectangleF rectangleFLine = new RectangleF();
- private DataGridViewTextBoxColumn Column1;
- private DataGridViewTextBoxColumn Column2;
- private DataGridViewTextBoxColumn Column3;
- private DataGridViewTextBoxColumn Column4;
- private DataGridViewTextBoxColumn Column5;
- private ListView listView2;
- private GroupBox groupBox6;
- private Label label2;
- private Panel panel2;
- private RadioButton radioButton2;
- private RadioButton radioButton1;
- private GroupBox groupBox9;
- private CheckBox checkBox10;
- private HistogramControl histogramControl1;
- private DecimalScopeControl numberScopeControl3;
- private DecimalScopeControl numberScopeControl2;
- private DecimalScopeControl numberScopeControl1;
- private CheckBox checkBox5;
- private Button button7;
- private Button button6;
- private CheckBox checkBox11;
- private GroupBox groupBox4;
- private Label label8;
- private NumericUpDown numericUpDown2;
- private NumericUpDown numericUpDown1;
- private CheckBox checkBox2;
- private TextBox textBox6;
- private Label label7;
- private ComboBox comboBox3;
- private Label label6;
- private ComboBox comboBox2;
- private Label label1;
- private CheckBox checkBox1;
- private Panel panel1;
- private Button button3;
- public bool comboboxChange = true;
- /// <summary>
- ///
- /// </summary>
- /// <param name="appWorkspace"></param>
- /// <param name="gbtType">0,GBT6394; ; 2,GBT24177; 3,E112; 4,ISO643</param>
- public GrainSizeBoundryEditDialog(AppWorkspace appWorkspace, int gbtType)
- {
- InitializeComponent();
- this.appWorkspace = appWorkspace;
- this.gbtType = gbtType;
- this.button11.Visible = true;
- this.button16.Visible = false;
- //
- //二值化相关
- //
- this.colorsFormGrid = new ColorsForm();
- this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
- this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
- //二值化end
- //
- //初始化图像控件
- //
- this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
- this.documentWorkspace.Dock = DockStyle.Fill;
- this.documentWorkspace.HookMouseEvents();
- this.documentWorkspace.AuxiliaryLineEnabled = false;
- this.documentWorkspace.Visible = false;
- this.documentWorkspace.panel.MouseDown += OnMouseDown;
- this.documentWorkspace.panel.Paint += Panel_Paint;
- this.documentWorkspace.panel.MouseMove += onMouseMove;
- this.documentWorkspace.panel.MouseUp += onMouseUp;
- this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click);
- this.groupBox7.Controls.Add(documentWorkspace);
- //
- //初始化操作按钮
- //
- this.commonControlButtons = new CommonControlButtons();
- this.commonControlButtons.Dock = DockStyle.Top;
- this.commonControlButtons.Height = 30;
- this.commonControlButtons.HideZoomToWindowAndActualSize();
- this.groupBox7.Controls.Add(commonControlButtons);
- {
- //二值化相关
- PhaseModel model = new PhaseModel();
- model.choise = true;
- model.mat = null;
- model.color = panel2.BackColor.ToArgb();
- model.position = this.documentWorkspace.PhaseModels.Count + 1;
- model.name = "二值提取";
- this.documentWorkspace.PhaseModels.Add(model);
- //二值化end
- }
- {
- //
- //初始化相
- //
- PhaseModel model = new PhaseModel();
- model.choise = true;
- model.mat = null;
- model.color = Color.Green/*panel2.BackColor*/.ToArgb();
- model.position = this.documentWorkspace.PhaseModels.Count + 1;
- model.name = "晶界重现";
- this.documentWorkspace.PhaseModels.Add(model);
- }
- {
- //
- //初始化相
- //
- PhaseModel model = new PhaseModel();
- model.choise = true;
- model.mat = null;
- model.color = Color.Green/*panel2.BackColor*/.ToArgb();
- model.position = this.documentWorkspace.PhaseModels.Count + 1;
- model.name = "用不同颜色显示晶粒";
- this.documentWorkspace.PhaseModels.Add(model);
- }
- //初始化头
- this.listView2.View = View.Details;
- ColumnHeader header0 = new ColumnHeader();
- header0.Text = "";
- header0.Width = 180;
- this.listView2.Columns.Add(header0);
- //二值化相关
- InitParameterList();
- InitParameterToControl();
- InitHistogramDragEvent();
- //二值化end
- InitPicList();
- InitComboboxValue(null);
- UpdateCupOffPointStyle();
- //InitHistogramDragEvent();
- InitCommonButtonEvent();
- }
- #region 二值化相关 初始化
- private void InitHistogramDragEvent()
- {
- this.histogramControl1.DragOneEventActionFinish += new EventHandler<EventArgs<int>>(this.DragOneEvent);
- this.histogramControl1.DragTwoEventActionFinish += new EventHandler<EventArgs<int>>(this.DragTwoEvent);
- this.histogramControl1.DragThreeEventActionFinish += new EventHandler<EventArgs<int>>(this.DragThreeEvent);
- this.histogramControl1.DragFourEventActionFinish += new EventHandler<EventArgs<int>>(this.DragFourEvent);
- }
- /// <summary>
- /// 颜色区间2 截止值变化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void DragFourEvent(object sender, EventArgs<int> e)
- {
- this.numberScopeControl2.maxValue = e.Data;
- }
- /// <summary>
- /// 颜色区间2 起始值变化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void DragThreeEvent(object sender, EventArgs<int> e)
- {
- this.numberScopeControl2.minValue = e.Data;
- }
- /// <summary>
- /// 颜色区间1 截止值变化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void DragTwoEvent(object sender, EventArgs<int> e)
- {
- if (this.binaryExtractionModel.ColorInterval == 1)
- {
- this.numberScopeControl1.maxValue = e.Data;
- }
- else if (this.binaryExtractionModel.ColorInterval == 2)
- {
- this.numberScopeControl3.maxValue = e.Data;
- }
- }
- /// <summary>
- /// 颜色区间1 起始值变化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void DragOneEvent(object sender, EventArgs<int> e)
- {
- if (this.binaryExtractionModel.ColorInterval == 1)
- {
- this.numberScopeControl1.minValue = e.Data;
- }
- else if (this.binaryExtractionModel.ColorInterval == 2)
- {
- this.numberScopeControl3.minValue = e.Data;
- }
- }
- /// <summary>
- /// 把参数的值设置到控件上
- /// </summary>
- public void InitParameterToControl()
- {
- if (this.binaryExtractionModel != null)
- {
- //阈值相关
- //1个颜色区间还是2个
- if (this.binaryExtractionModel.ColorInterval == 1)
- {
- this.numberScopeControl2.Visible = false;
- this.numberScopeControl3.Visible = false;
- this.button6.Text = "反选";
- }
- else
- {
- this.numberScopeControl2.Visible = true;
- this.numberScopeControl3.Visible = true;
- this.button6.Text = "取消反选";
- }
- //删除事件
- this.DeleteEventHandler();
- this.numberScopeControl1.maxValue = this.binaryExtractionModel.ColorOneEnd;
- this.numberScopeControl1.minValue = this.binaryExtractionModel.ColorOneStart;
- this.numberScopeControl2.maxValue = this.binaryExtractionModel.ColorTwoEnd;
- this.numberScopeControl2.minValue = this.binaryExtractionModel.ColorTwoStart;
- this.numberScopeControl3.maxValue = this.binaryExtractionModel.ColorThreeEnd;
- this.numberScopeControl3.minValue = this.binaryExtractionModel.ColorThreeStart;
- if (this.binaryExtractionModel.BinaryStyle == 1) this.radioButton1.Checked = true;
- if (this.binaryExtractionModel.BinaryStyle == 2) this.radioButton2.Checked = true;
- this.panel2.BackColor = Color.FromArgb(this.binaryExtractionModel.PhaseColor);
- //添加事件
- this.AddEventHandler();
- if (this.binaryExtractionModel.ColorInterval == 1)
- {
- //处理直方图
- this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue));
- }
- else
- {
- //处理直方图
- this.histogramControl1.UpdateVerticalBarWithTwoScope(
- (int)(this.numberScopeControl3.minValue),
- (int)(this.numberScopeControl3.maxValue),
- (int)(this.numberScopeControl2.minValue),
- (int)(this.numberScopeControl2.maxValue)
- );
- }
- this.applyButtonImpl(null, null);
- }
- }
- private void DeleteEventHandler()
- {
- this.numberScopeControl1.ValueChanged -= this.numberScope1_ValueChanged;
- this.numberScopeControl1.numericUpDown1.KeyUp -= this.numberScope1_ValueChanged;
- this.numberScopeControl1.numericUpDown2.KeyUp -= this.numberScope1_ValueChanged;
- this.numberScopeControl3.numericUpDown2.KeyUp -= this.applyButtonImpl;
- this.numberScopeControl2.ValueChanged -= this.numberScope2_ValueChanged;
- this.numberScopeControl2.numericUpDown1.KeyUp -= this.numberScope2_ValueChanged;
- this.numberScopeControl2.numericUpDown2.KeyUp -= this.numberScope2_ValueChanged;
- this.numberScopeControl3.ValueChanged -= this.numberScope3_ValueChanged;
- this.numberScopeControl3.numericUpDown1.KeyUp -= this.numberScope3_ValueChanged;
- this.numberScopeControl3.numericUpDown2.KeyUp -= this.numberScope3_ValueChanged;
- this.numberScopeControl1.ValueChanged -= this.applyButtonImpl;
- this.numberScopeControl2.ValueChanged -= this.applyButtonImpl;
- this.numberScopeControl3.ValueChanged -= this.applyButtonImpl;
- this.radioButton1.CheckedChanged -= this.applyButtonImpl;
- this.radioButton2.CheckedChanged -= this.applyButtonImpl;
- this.panel2.BackColorChanged -= this.applyButtonImpl;
- }
- private void AddEventHandler()
- {
- this.numberScopeControl1.ValueChanged += this.numberScope1_ValueChanged;
- this.numberScopeControl1.numericUpDown1.KeyUp += this.numberScope1_ValueChanged;
- this.numberScopeControl1.numericUpDown2.KeyUp += this.numberScope1_ValueChanged;
- this.numberScopeControl3.numericUpDown2.KeyUp += this.applyButtonImpl;
- this.numberScopeControl2.ValueChanged += this.numberScope2_ValueChanged;
- this.numberScopeControl2.numericUpDown1.KeyUp += this.numberScope2_ValueChanged;
- this.numberScopeControl2.numericUpDown2.KeyUp += this.numberScope2_ValueChanged;
- this.numberScopeControl3.ValueChanged += this.numberScope3_ValueChanged;
- this.numberScopeControl3.numericUpDown1.KeyUp += this.numberScope3_ValueChanged;
- this.numberScopeControl3.numericUpDown2.KeyUp += this.numberScope3_ValueChanged;
- this.numberScopeControl1.ValueChanged += this.applyButtonImpl;
- this.numberScopeControl2.ValueChanged += this.applyButtonImpl;
- this.numberScopeControl3.ValueChanged += this.applyButtonImpl;
- this.radioButton1.CheckedChanged += this.applyButtonImpl;
- this.radioButton2.CheckedChanged += this.applyButtonImpl;
- this.panel2.BackColorChanged += this.applyButtonImpl;
- }
- /// <summary>
- /// 初始化参数配置下拉
- /// </summary>
- public void InitParameterList(int index = 0)
- {
- List<string> fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\");
- files.Clear();
- foreach (string fileName in fileNames)
- {
- string name = fileName.Substring(0, fileName.LastIndexOf("."));
- files.Add(name);
- }
- //this.comboBox1.SelectedIndexChanged -= this.comboBox1_SelectedIndexChanged;//##############
- //this.comboBox1.DataSource = null;
- //this.comboBox1.DataSource = files;
- string nowModelName = Startup.instance.configModel.BinaryParameter.Substring(0, Startup.instance.configModel.Watermark.LastIndexOf("."));
- //if (index != 0)
- //{
- // if (this.files.Count > index)
- // {
- // this.comboBox1.SelectedIndex = index;
- // }
- // else
- // {
- // this.comboBox1.SelectedIndex = 0;
- // }
- //}
- //else
- //{
- // this.comboBox1.SelectedIndex = files.FindIndex(a => a.Equals(nowModelName));
- //}
- this.binaryExtractionModel = XmlSerializeHelper.DESerializer<BinaryExtractionModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\BinaryExtraction\\Default.xml", FileMode.Open));/*" + this.comboBox1.SelectedItem.ToString() + "*///##############
- //this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
- }
- #endregion
- private void InitCommonButtonEvent()
- {
- this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
- this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
- this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
- this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
- this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
- this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
- }
- private void zoomInButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomIn();
- }
- private void zoomOutButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomOut();
- }
- private void zoomToWindowButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- private void actualSizeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
- }
- private void pointerButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
- }
- private void mobileModeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
- }
- /// <summary>
- /// 初始化图片列表数据
- /// </summary>
- public void InitPicList()
- {
- //初始化图片列表
- for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
- {
- this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.Thumbnail);
- this.listView1.Items.Add("", i);
- this.listView1.Items[i].ImageIndex = i;
- this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- }
- }
- #region 初始化
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.button2 = new System.Windows.Forms.Button();
- this.checkBox2_0 = new System.Windows.Forms.CheckBox();
- this.button1 = new System.Windows.Forms.Button();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.listView1 = new System.Windows.Forms.ListView();
- this.imageList1 = new System.Windows.Forms.ImageList(this.components);
- this.button9 = new System.Windows.Forms.Button();
- this.groupBox8 = new System.Windows.Forms.GroupBox();
- this.listView2 = new System.Windows.Forms.ListView();
- this.numericUpDown1_0 = new System.Windows.Forms.NumericUpDown();
- this.button16 = new System.Windows.Forms.Button();
- this.label5 = new System.Windows.Forms.Label();
- this.button14 = new System.Windows.Forms.Button();
- this.button13 = new System.Windows.Forms.Button();
- this.dataGridView4 = new System.Windows.Forms.DataGridView();
- this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.button12 = new System.Windows.Forms.Button();
- this.button11 = new System.Windows.Forms.Button();
- this.label4 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.groupBox7 = new System.Windows.Forms.GroupBox();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.groupBox11 = new System.Windows.Forms.GroupBox();
- this.panel1 = new System.Windows.Forms.Panel();
- this.checkBox11 = new System.Windows.Forms.CheckBox();
- this.checkBox5_0 = new System.Windows.Forms.CheckBox();
- this.checkBox4_0 = new System.Windows.Forms.CheckBox();
- this.checkBox3_0 = new System.Windows.Forms.CheckBox();
- this.groupBox6 = new System.Windows.Forms.GroupBox();
- this.label2 = new System.Windows.Forms.Label();
- this.panel2 = new System.Windows.Forms.Panel();
- this.radioButton2 = new System.Windows.Forms.RadioButton();
- this.radioButton1 = new System.Windows.Forms.RadioButton();
- this.groupBox9 = new System.Windows.Forms.GroupBox();
- this.checkBox10 = new System.Windows.Forms.CheckBox();
- this.histogramControl1 = new PaintDotNet.CustomControl.HistogramControl();
- this.numberScopeControl3 = new PaintDotNet.CustomControl.DecimalScopeControl();
- this.numberScopeControl2 = new PaintDotNet.CustomControl.DecimalScopeControl();
- this.numberScopeControl1 = new PaintDotNet.CustomControl.DecimalScopeControl();
- this.checkBox5 = new System.Windows.Forms.CheckBox();
- this.button7 = new System.Windows.Forms.Button();
- this.button6 = new System.Windows.Forms.Button();
- this.groupBox4 = new System.Windows.Forms.GroupBox();
- this.label8 = new System.Windows.Forms.Label();
- this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
- this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
- this.checkBox2 = new System.Windows.Forms.CheckBox();
- this.textBox6 = new System.Windows.Forms.TextBox();
- this.label7 = new System.Windows.Forms.Label();
- this.comboBox3 = new System.Windows.Forms.ComboBox();
- this.label6 = new System.Windows.Forms.Label();
- this.comboBox2 = new System.Windows.Forms.ComboBox();
- this.label1 = new System.Windows.Forms.Label();
- this.checkBox1 = new System.Windows.Forms.CheckBox();
- this.button3 = new System.Windows.Forms.Button();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- this.groupBox8.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView4)).BeginInit();
- this.groupBox3.SuspendLayout();
- this.groupBox11.SuspendLayout();
- this.groupBox6.SuspendLayout();
- this.groupBox9.SuspendLayout();
- this.groupBox4.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.button2);
- this.groupBox1.Controls.Add(this.checkBox2_0);
- this.groupBox1.Controls.Add(this.button1);
- this.groupBox1.Location = new System.Drawing.Point(14, 3);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(1081, 50);
- this.groupBox1.TabIndex = 2;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "操作";
- //
- // button2
- //
- this.button2.BackColor = System.Drawing.SystemColors.Control;
- this.button2.Location = new System.Drawing.Point(985, 14);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(84, 30);
- this.button2.TabIndex = 3;
- this.button2.Text = "保存结果";
- this.button2.UseVisualStyleBackColor = false;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // checkBox2_0
- //
- this.checkBox2_0.AutoSize = true;
- this.checkBox2_0.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
- this.checkBox2_0.Location = new System.Drawing.Point(138, 22);
- this.checkBox2_0.Name = "checkBox2_0";
- this.checkBox2_0.Size = new System.Drawing.Size(132, 16);
- this.checkBox2_0.TabIndex = 2;
- this.checkBox2_0.Text = "生成报告时打开设置";
- this.checkBox2_0.UseVisualStyleBackColor = true;
- //
- // button1
- //
- this.button1.BackColor = System.Drawing.SystemColors.Control;
- this.button1.Location = new System.Drawing.Point(15, 14);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(84, 30);
- this.button1.TabIndex = 0;
- this.button1.Text = "设置";
- this.button1.UseVisualStyleBackColor = false;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // groupBox2
- //
- this.groupBox2.Controls.Add(this.listView1);
- this.groupBox2.Location = new System.Drawing.Point(14, 59);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(135, 561);
- this.groupBox2.TabIndex = 3;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "图像索引";
- //
- // listView1
- //
- this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.listView1.HideSelection = false;
- this.listView1.LargeImageList = this.imageList1;
- this.listView1.Location = new System.Drawing.Point(5, 17);
- this.listView1.MultiSelect = false;
- this.listView1.Name = "listView1";
- this.listView1.Size = new System.Drawing.Size(124, 538);
- this.listView1.TabIndex = 0;
- this.listView1.UseCompatibleStateImageBehavior = false;
- this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
- //
- // imageList1
- //
- this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
- this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
- this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
- //
- // button9
- //
- this.button9.BackColor = System.Drawing.SystemColors.Control;
- this.button9.Location = new System.Drawing.Point(241, 19);
- this.button9.Name = "button9";
- this.button9.Size = new System.Drawing.Size(92, 26);
- this.button9.TabIndex = 10;
- this.button9.Text = "辅助线设置";
- this.button9.UseVisualStyleBackColor = false;
- this.button9.Click += new System.EventHandler(this.button9_Click);
- //
- // groupBox8
- //
- this.groupBox8.Controls.Add(this.listView2);
- this.groupBox8.Controls.Add(this.numericUpDown1_0);
- this.groupBox8.Controls.Add(this.button16);
- this.groupBox8.Controls.Add(this.label5);
- this.groupBox8.Controls.Add(this.button14);
- this.groupBox8.Controls.Add(this.button13);
- this.groupBox8.Controls.Add(this.dataGridView4);
- this.groupBox8.Controls.Add(this.button12);
- this.groupBox8.Controls.Add(this.button11);
- this.groupBox8.Controls.Add(this.label4);
- this.groupBox8.Controls.Add(this.label3);
- this.groupBox8.Location = new System.Drawing.Point(14, 626);
- this.groupBox8.Name = "groupBox8";
- this.groupBox8.Size = new System.Drawing.Size(1081, 204);
- this.groupBox8.TabIndex = 10;
- this.groupBox8.TabStop = false;
- this.groupBox8.Text = "分析结果";
- //
- // listView2
- //
- this.listView2.FullRowSelect = true;
- this.listView2.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
- this.listView2.HideSelection = false;
- this.listView2.Location = new System.Drawing.Point(15, 56);
- this.listView2.MultiSelect = false;
- this.listView2.Name = "listView2";
- this.listView2.Size = new System.Drawing.Size(181, 140);
- this.listView2.TabIndex = 24;
- this.listView2.UseCompatibleStateImageBehavior = false;
- this.listView2.SelectedIndexChanged += new System.EventHandler(this.listView2_SelectedIndexChanged);
- //
- // numericUpDown1_0
- //
- this.numericUpDown1_0.Location = new System.Drawing.Point(997, 163);
- this.numericUpDown1_0.Maximum = new decimal(new int[] {
- 10,
- 0,
- 0,
- 0});
- this.numericUpDown1_0.Name = "numericUpDown1_0";
- this.numericUpDown1_0.Size = new System.Drawing.Size(56, 21);
- this.numericUpDown1_0.TabIndex = 21;
- this.numericUpDown1_0.Value = new decimal(new int[] {
- 2,
- 0,
- 0,
- 0});
- this.numericUpDown1_0.ValueChanged += new System.EventHandler(this.numericUpDown1_0_ValueChanged);
- //
- // button16
- //
- this.button16.BackColor = System.Drawing.SystemColors.Control;
- this.button16.Location = new System.Drawing.Point(15, 20);
- this.button16.Name = "button16";
- this.button16.Size = new System.Drawing.Size(93, 26);
- this.button16.TabIndex = 20;
- this.button16.Text = "取消全部显示";
- this.button16.UseVisualStyleBackColor = false;
- this.button16.Click += new System.EventHandler(this.button16_Click);
- //
- // label5
- //
- this.label5.AutoSize = true;
- this.label5.Location = new System.Drawing.Point(958, 169);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(41, 12);
- this.label5.TabIndex = 18;
- this.label5.Text = "小数:";
- //
- // button14
- //
- this.button14.BackColor = System.Drawing.SystemColors.Control;
- this.button14.Location = new System.Drawing.Point(941, 71);
- this.button14.Name = "button14";
- this.button14.Size = new System.Drawing.Size(128, 26);
- this.button14.TabIndex = 16;
- this.button14.Text = "导出结果";
- this.button14.UseVisualStyleBackColor = false;
- this.button14.Click += new System.EventHandler(this.button14_Click);
- //
- // button13
- //
- this.button13.BackColor = System.Drawing.SystemColors.Control;
- this.button13.Location = new System.Drawing.Point(941, 34);
- this.button13.Name = "button13";
- this.button13.Size = new System.Drawing.Size(128, 26);
- this.button13.TabIndex = 12;
- this.button13.Text = "生成报告";
- this.button13.UseVisualStyleBackColor = false;
- this.button13.Click += new System.EventHandler(this.button13_Click);
- //
- // dataGridView4
- //
- this.dataGridView4.AllowUserToAddRows = false;
- this.dataGridView4.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
- this.dataGridView4.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
- dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
- dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
- dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F);
- dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
- dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
- dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
- dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
- this.dataGridView4.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
- this.dataGridView4.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.dataGridView4.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- this.Column1,
- this.Column2,
- this.Column3,
- this.Column4,
- this.Column5});
- this.dataGridView4.Location = new System.Drawing.Point(228, 20);
- this.dataGridView4.Name = "dataGridView4";
- this.dataGridView4.ReadOnly = true;
- this.dataGridView4.RowHeadersVisible = false;
- this.dataGridView4.RowTemplate.Height = 23;
- this.dataGridView4.Size = new System.Drawing.Size(693, 176);
- this.dataGridView4.TabIndex = 15;
- //
- // Column1
- //
- this.Column1.HeaderText = "图片";
- this.Column1.Name = "Column1";
- this.Column1.ReadOnly = true;
- //
- // Column2
- //
- this.Column2.HeaderText = "网格";
- this.Column2.Name = "Column2";
- this.Column2.ReadOnly = true;
- //
- // Column3
- //
- this.Column3.HeaderText = "网格面积";
- this.Column3.Name = "Column3";
- this.Column3.ReadOnly = true;
- //
- // Column4
- //
- this.Column4.HeaderText = "晶粒数";
- this.Column4.Name = "Column4";
- this.Column4.ReadOnly = true;
- //
- // Column5
- //
- this.Column5.HeaderText = "平均晶粒度级别";
- this.Column5.Name = "Column5";
- this.Column5.ReadOnly = true;
- //
- // button12
- //
- this.button12.BackColor = System.Drawing.SystemColors.Control;
- this.button12.Location = new System.Drawing.Point(145, 20);
- this.button12.Name = "button12";
- this.button12.Size = new System.Drawing.Size(52, 26);
- this.button12.TabIndex = 13;
- this.button12.Text = "删除";
- this.button12.UseVisualStyleBackColor = false;
- this.button12.Click += new System.EventHandler(this.button12_Click);
- //
- // button11
- //
- this.button11.BackColor = System.Drawing.SystemColors.Control;
- this.button11.Location = new System.Drawing.Point(15, 20);
- this.button11.Name = "button11";
- this.button11.Size = new System.Drawing.Size(63, 26);
- this.button11.TabIndex = 12;
- this.button11.Text = "全部显示";
- this.button11.UseVisualStyleBackColor = false;
- this.button11.Click += new System.EventHandler(this.button11_Click);
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.ForeColor = System.Drawing.SystemColors.ScrollBar;
- this.label4.Location = new System.Drawing.Point(924, 9);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(11, 192);
- this.label4.TabIndex = 1;
- this.label4.Text = "|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|";
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.ForeColor = System.Drawing.SystemColors.ScrollBar;
- this.label3.Location = new System.Drawing.Point(214, 9);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(11, 192);
- this.label3.TabIndex = 0;
- this.label3.Text = "|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|\r\n|";
- //
- // groupBox7
- //
- this.groupBox7.Location = new System.Drawing.Point(515, 59);
- this.groupBox7.Name = "groupBox7";
- this.groupBox7.Size = new System.Drawing.Size(580, 561);
- this.groupBox7.TabIndex = 11;
- this.groupBox7.TabStop = false;
- this.groupBox7.Text = "预览";
- //
- // groupBox3
- //
- this.groupBox3.Controls.Add(this.button9);
- this.groupBox3.Controls.Add(this.comboBox1);
- this.groupBox3.Location = new System.Drawing.Point(153, 487);
- this.groupBox3.Name = "groupBox3";
- this.groupBox3.Size = new System.Drawing.Size(355, 50);
- this.groupBox3.TabIndex = 12;
- this.groupBox3.TabStop = false;
- this.groupBox3.Text = "网格";
- //
- // comboBox1
- //
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new System.Drawing.Point(15, 22);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(220, 20);
- this.comboBox1.TabIndex = 0;
- this.comboBox1.Text = "请选择使用的辅助线";
- this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- //
- // groupBox11
- //
- this.groupBox11.Controls.Add(this.panel1);
- this.groupBox11.Controls.Add(this.checkBox11);
- this.groupBox11.Controls.Add(this.checkBox5_0);
- this.groupBox11.Controls.Add(this.checkBox4_0);
- this.groupBox11.Controls.Add(this.checkBox3_0);
- this.groupBox11.Location = new System.Drawing.Point(152, 538);
- this.groupBox11.Name = "groupBox11";
- this.groupBox11.Size = new System.Drawing.Size(356, 82);
- this.groupBox11.TabIndex = 17;
- this.groupBox11.TabStop = false;
- this.groupBox11.Text = "显示参数设置";
- //
- // panel1
- //
- this.panel1.BackColor = System.Drawing.Color.Red;
- this.panel1.Location = new System.Drawing.Point(252, 22);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(72, 21);
- this.panel1.TabIndex = 20;
- this.panel1.Click += new System.EventHandler(this.panel1_Click);
- //
- // checkBox11
- //
- this.checkBox11.AutoSize = true;
- this.checkBox11.Checked = true;
- this.checkBox11.CheckState = System.Windows.Forms.CheckState.Checked;
- this.checkBox11.Location = new System.Drawing.Point(139, 49);
- this.checkBox11.Name = "checkBox11";
- this.checkBox11.Size = new System.Drawing.Size(132, 16);
- this.checkBox11.TabIndex = 3;
- this.checkBox11.Text = "用不同颜色显示晶粒";
- this.checkBox11.UseVisualStyleBackColor = true;
- this.checkBox11.CheckedChanged += new System.EventHandler(this.checkBox11_CheckedChanged);
- //
- // checkBox5_0
- //
- this.checkBox5_0.AutoSize = true;
- this.checkBox5_0.Checked = true;
- this.checkBox5_0.CheckState = System.Windows.Forms.CheckState.Checked;
- this.checkBox5_0.Location = new System.Drawing.Point(140, 27);
- this.checkBox5_0.Name = "checkBox5_0";
- this.checkBox5_0.Size = new System.Drawing.Size(96, 16);
- this.checkBox5_0.TabIndex = 2;
- this.checkBox5_0.Text = "显示晶粒编号";
- this.checkBox5_0.UseVisualStyleBackColor = true;
- this.checkBox5_0.CheckedChanged += new System.EventHandler(this.checkBox5_0_CheckedChanged);
- //
- // checkBox4_0
- //
- this.checkBox4_0.AutoSize = true;
- this.checkBox4_0.Checked = true;
- this.checkBox4_0.CheckState = System.Windows.Forms.CheckState.Checked;
- this.checkBox4_0.Location = new System.Drawing.Point(15, 49);
- this.checkBox4_0.Name = "checkBox4_0";
- this.checkBox4_0.Size = new System.Drawing.Size(72, 16);
- this.checkBox4_0.TabIndex = 1;
- this.checkBox4_0.Text = "显示网格";
- this.checkBox4_0.UseVisualStyleBackColor = true;
- this.checkBox4_0.CheckedChanged += new System.EventHandler(this.checkBox4_0_CheckedChanged);
- //
- // checkBox3_0
- //
- this.checkBox3_0.AutoSize = true;
- this.checkBox3_0.Checked = true;
- this.checkBox3_0.CheckState = System.Windows.Forms.CheckState.Checked;
- this.checkBox3_0.Location = new System.Drawing.Point(15, 27);
- this.checkBox3_0.Name = "checkBox3_0";
- this.checkBox3_0.Size = new System.Drawing.Size(72, 16);
- this.checkBox3_0.TabIndex = 0;
- this.checkBox3_0.Text = "显示晶界";
- this.checkBox3_0.UseVisualStyleBackColor = true;
- this.checkBox3_0.CheckedChanged += new System.EventHandler(this.checkBox3_0_CheckedChanged);
- //
- // groupBox6
- //
- this.groupBox6.Controls.Add(this.label2);
- this.groupBox6.Controls.Add(this.panel2);
- this.groupBox6.Controls.Add(this.radioButton2);
- this.groupBox6.Controls.Add(this.radioButton1);
- this.groupBox6.Location = new System.Drawing.Point(153, 283);
- this.groupBox6.Name = "groupBox6";
- this.groupBox6.Size = new System.Drawing.Size(356, 54);
- this.groupBox6.TabIndex = 24;
- this.groupBox6.TabStop = false;
- this.groupBox6.Text = "二值样式";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(105, 34);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(53, 12);
- this.label2.TabIndex = 20;
- this.label2.Text = "相颜色:";
- //
- // panel2
- //
- this.panel2.BackColor = System.Drawing.Color.Red;
- this.panel2.Location = new System.Drawing.Point(160, 29);
- this.panel2.Name = "panel2";
- this.panel2.Size = new System.Drawing.Size(72, 21);
- this.panel2.TabIndex = 19;
- this.panel2.Click += new System.EventHandler(this.panel2_Click);
- //
- // radioButton2
- //
- this.radioButton2.AutoSize = true;
- this.radioButton2.Location = new System.Drawing.Point(56, 32);
- this.radioButton2.Name = "radioButton2";
- this.radioButton2.Size = new System.Drawing.Size(47, 16);
- this.radioButton2.TabIndex = 1;
- this.radioButton2.Text = "边线";
- this.radioButton2.UseVisualStyleBackColor = true;
- this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
- //
- // radioButton1
- //
- this.radioButton1.AutoSize = true;
- this.radioButton1.Checked = true;
- this.radioButton1.Location = new System.Drawing.Point(7, 32);
- this.radioButton1.Name = "radioButton1";
- this.radioButton1.Size = new System.Drawing.Size(47, 16);
- this.radioButton1.TabIndex = 0;
- this.radioButton1.TabStop = true;
- this.radioButton1.Text = "实心";
- this.radioButton1.UseVisualStyleBackColor = true;
- this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
- //
- // groupBox9
- //
- this.groupBox9.Controls.Add(this.checkBox10);
- this.groupBox9.Controls.Add(this.histogramControl1);
- this.groupBox9.Controls.Add(this.numberScopeControl3);
- this.groupBox9.Controls.Add(this.numberScopeControl2);
- this.groupBox9.Controls.Add(this.numberScopeControl1);
- this.groupBox9.Controls.Add(this.checkBox5);
- this.groupBox9.Controls.Add(this.button7);
- this.groupBox9.Controls.Add(this.button6);
- this.groupBox9.Location = new System.Drawing.Point(153, 59);
- this.groupBox9.Name = "groupBox9";
- this.groupBox9.Size = new System.Drawing.Size(356, 218);
- this.groupBox9.TabIndex = 22;
- this.groupBox9.TabStop = false;
- this.groupBox9.Text = "直方图";
- //
- // checkBox10
- //
- this.checkBox10.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.checkBox10.AutoSize = true;
- this.checkBox10.Location = new System.Drawing.Point(234, 195);
- this.checkBox10.Name = "checkBox10";
- this.checkBox10.Size = new System.Drawing.Size(60, 16);
- this.checkBox10.TabIndex = 17;
- this.checkBox10.Text = "二值化";
- this.checkBox10.UseVisualStyleBackColor = true;
- this.checkBox10.CheckedChanged += new System.EventHandler(this.checkBox10_CheckedChanged);
- //
- // histogramControl1
- //
- this.histogramControl1.Flag = 1;
- this.histogramControl1.Location = new System.Drawing.Point(8, 22);
- this.histogramControl1.Name = "histogramControl1";
- this.histogramControl1.Size = new System.Drawing.Size(340, 130);
- this.histogramControl1.TabIndex = 16;
- //
- // numberScopeControl3
- //
- this.numberScopeControl3.DecimalPlaces = 0;
- this.numberScopeControl3.Location = new System.Drawing.Point(8, 158);
- this.numberScopeControl3.Maximum = 255D;
- this.numberScopeControl3.maxValue = 0D;
- this.numberScopeControl3.Minimum = 0D;
- this.numberScopeControl3.minValue = 0D;
- this.numberScopeControl3.Name = "numberScopeControl3";
- this.numberScopeControl3.Size = new System.Drawing.Size(150, 22);
- this.numberScopeControl3.TabIndex = 15;
- this.numberScopeControl3.Visible = false;
- //
- // numberScopeControl2
- //
- this.numberScopeControl2.DecimalPlaces = 0;
- this.numberScopeControl2.Location = new System.Drawing.Point(186, 158);
- this.numberScopeControl2.Maximum = 255D;
- this.numberScopeControl2.maxValue = 0D;
- this.numberScopeControl2.Minimum = 0D;
- this.numberScopeControl2.minValue = 0D;
- this.numberScopeControl2.Name = "numberScopeControl2";
- this.numberScopeControl2.Size = new System.Drawing.Size(150, 22);
- this.numberScopeControl2.TabIndex = 14;
- this.numberScopeControl2.Visible = false;
- //
- // numberScopeControl1
- //
- this.numberScopeControl1.DecimalPlaces = 0;
- this.numberScopeControl1.Location = new System.Drawing.Point(8, 158);
- this.numberScopeControl1.Maximum = 255D;
- this.numberScopeControl1.maxValue = 0D;
- this.numberScopeControl1.Minimum = 0D;
- this.numberScopeControl1.minValue = 0D;
- this.numberScopeControl1.Name = "numberScopeControl1";
- this.numberScopeControl1.Size = new System.Drawing.Size(150, 22);
- this.numberScopeControl1.TabIndex = 13;
- this.numberScopeControl1.Tag = "numberScopeControl1";
- //
- // checkBox5
- //
- this.checkBox5.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.checkBox5.AutoSize = true;
- this.checkBox5.Location = new System.Drawing.Point(300, 195);
- this.checkBox5.Name = "checkBox5";
- this.checkBox5.Size = new System.Drawing.Size(48, 16);
- this.checkBox5.TabIndex = 11;
- this.checkBox5.Text = "原图";
- this.checkBox5.UseVisualStyleBackColor = true;
- this.checkBox5.CheckedChanged += new System.EventHandler(this.ShowOrHideOriginPic);
- //
- // button7
- //
- this.button7.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.button7.Location = new System.Drawing.Point(109, 191);
- this.button7.Name = "button7";
- this.button7.Size = new System.Drawing.Size(75, 23);
- this.button7.TabIndex = 12;
- this.button7.Text = "自动阈值";
- this.button7.UseVisualStyleBackColor = true;
- this.button7.Click += new System.EventHandler(this.button7_Click);
- //
- // button6
- //
- this.button6.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.button6.Location = new System.Drawing.Point(8, 191);
- this.button6.Name = "button6";
- this.button6.Size = new System.Drawing.Size(75, 23);
- this.button6.TabIndex = 11;
- this.button6.Text = "反选";
- this.button6.UseVisualStyleBackColor = true;
- this.button6.Click += new System.EventHandler(this.button6_Click);
- //
- // groupBox4
- //
- this.groupBox4.Controls.Add(this.button3);
- this.groupBox4.Controls.Add(this.label8);
- this.groupBox4.Controls.Add(this.numericUpDown2);
- this.groupBox4.Controls.Add(this.numericUpDown1);
- this.groupBox4.Controls.Add(this.checkBox2);
- this.groupBox4.Controls.Add(this.textBox6);
- this.groupBox4.Controls.Add(this.label7);
- this.groupBox4.Controls.Add(this.comboBox3);
- this.groupBox4.Controls.Add(this.label6);
- this.groupBox4.Controls.Add(this.comboBox2);
- this.groupBox4.Controls.Add(this.label1);
- this.groupBox4.Controls.Add(this.checkBox1);
- this.groupBox4.Location = new System.Drawing.Point(153, 343);
- this.groupBox4.Name = "groupBox4";
- this.groupBox4.Size = new System.Drawing.Size(356, 138);
- this.groupBox4.TabIndex = 25;
- this.groupBox4.TabStop = false;
- this.groupBox4.Text = "晶界重现";
- //
- // label8
- //
- this.label8.AutoSize = true;
- this.label8.Location = new System.Drawing.Point(6, 108);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(65, 12);
- this.label8.TabIndex = 30;
- this.label8.Text = "晶界大小:";
- //
- // numericUpDown2
- //
- this.numericUpDown2.DecimalPlaces = 2;
- this.numericUpDown2.Location = new System.Drawing.Point(164, 104);
- this.numericUpDown2.Maximum = new decimal(new int[] {
- 1000,
- 0,
- 0,
- 0});
- this.numericUpDown2.Name = "numericUpDown2";
- this.numericUpDown2.Size = new System.Drawing.Size(61, 21);
- this.numericUpDown2.TabIndex = 29;
- this.numericUpDown2.Tag = "max";
- this.numericUpDown2.Value = new decimal(new int[] {
- 500,
- 0,
- 0,
- 0});
- this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged_1);
- //
- // numericUpDown1
- //
- this.numericUpDown1.DecimalPlaces = 2;
- this.numericUpDown1.Location = new System.Drawing.Point(85, 104);
- this.numericUpDown1.Maximum = new decimal(new int[] {
- 1000,
- 0,
- 0,
- 0});
- this.numericUpDown1.Name = "numericUpDown1";
- this.numericUpDown1.Size = new System.Drawing.Size(61, 21);
- this.numericUpDown1.TabIndex = 28;
- this.numericUpDown1.Tag = "min";
- this.numericUpDown1.Value = new decimal(new int[] {
- 1,
- 0,
- 0,
- 131072});
- this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged_1);
- //
- // checkBox2
- //
- this.checkBox2.AutoSize = true;
- this.checkBox2.Checked = true;
- this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked;
- this.checkBox2.Location = new System.Drawing.Point(8, 50);
- this.checkBox2.Name = "checkBox2";
- this.checkBox2.Size = new System.Drawing.Size(72, 16);
- this.checkBox2.TabIndex = 26;
- this.checkBox2.Text = "晶界增强";
- this.checkBox2.UseVisualStyleBackColor = true;
- this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
- //
- // textBox6
- //
- this.textBox6.Location = new System.Drawing.Point(65, 75);
- this.textBox6.Name = "textBox6";
- this.textBox6.Size = new System.Drawing.Size(45, 21);
- this.textBox6.TabIndex = 25;
- this.textBox6.Text = "0.5";
- this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged);
- //
- // label7
- //
- this.label7.AutoSize = true;
- this.label7.Location = new System.Drawing.Point(6, 79);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(53, 12);
- this.label7.TabIndex = 24;
- this.label7.Text = "西格玛:";
- //
- // comboBox3
- //
- this.comboBox3.FormattingEnabled = true;
- this.comboBox3.Items.AddRange(new object[] {
- "高斯平滑",
- "方向平滑"});
- this.comboBox3.Location = new System.Drawing.Point(201, 76);
- this.comboBox3.Name = "comboBox3";
- this.comboBox3.Size = new System.Drawing.Size(133, 20);
- this.comboBox3.TabIndex = 23;
- this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged);
- //
- // label6
- //
- this.label6.AutoSize = true;
- this.label6.Location = new System.Drawing.Point(136, 79);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(65, 12);
- this.label6.TabIndex = 22;
- this.label6.Text = "去噪类型:";
- //
- // comboBox2
- //
- this.comboBox2.FormattingEnabled = true;
- this.comboBox2.Items.AddRange(new object[] {
- "亮晶界",
- "暗晶界",
- "梯度"});
- this.comboBox2.Location = new System.Drawing.Point(201, 48);
- this.comboBox2.Name = "comboBox2";
- this.comboBox2.Size = new System.Drawing.Size(133, 20);
- this.comboBox2.TabIndex = 11;
- this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(136, 51);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(65, 12);
- this.label1.TabIndex = 21;
- this.label1.Text = "晶界类型:";
- //
- // checkBox1
- //
- this.checkBox1.AutoSize = true;
- this.checkBox1.Location = new System.Drawing.Point(8, 20);
- this.checkBox1.Name = "checkBox1";
- this.checkBox1.Size = new System.Drawing.Size(72, 16);
- this.checkBox1.TabIndex = 7;
- this.checkBox1.Text = "晶界重现";
- this.checkBox1.UseVisualStyleBackColor = true;
- this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
- //
- // button3
- //
- this.button3.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.button3.Location = new System.Drawing.Point(138, 16);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 31;
- this.button3.Text = "晶界编辑";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // GrainSizeBoundryEditDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(1107, 835);
- this.Controls.Add(this.groupBox4);
- this.Controls.Add(this.groupBox6);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox9);
- this.Controls.Add(this.groupBox11);
- this.Controls.Add(this.groupBox7);
- this.Controls.Add(this.groupBox8);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.Name = "GrainSizeBoundryEditDialog";
- this.Text = "晶粒度(面积法)";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GrainSizeDialog_FormClosing);
- this.Load += new System.EventHandler(this.GrainSizeDialog_Load);
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.Controls.SetChildIndex(this.groupBox8, 0);
- this.Controls.SetChildIndex(this.groupBox7, 0);
- this.Controls.SetChildIndex(this.groupBox11, 0);
- this.Controls.SetChildIndex(this.groupBox9, 0);
- this.Controls.SetChildIndex(this.groupBox3, 0);
- this.Controls.SetChildIndex(this.groupBox6, 0);
- this.Controls.SetChildIndex(this.groupBox4, 0);
- this.groupBox1.ResumeLayout(false);
- this.groupBox1.PerformLayout();
- this.groupBox2.ResumeLayout(false);
- this.groupBox8.ResumeLayout(false);
- this.groupBox8.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1_0)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView4)).EndInit();
- this.groupBox3.ResumeLayout(false);
- this.groupBox11.ResumeLayout(false);
- this.groupBox11.PerformLayout();
- this.groupBox6.ResumeLayout(false);
- this.groupBox6.PerformLayout();
- this.groupBox9.ResumeLayout(false);
- this.groupBox9.PerformLayout();
- this.groupBox4.ResumeLayout(false);
- this.groupBox4.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// 更新截点样式
- /// </summary>
- public void UpdateCupOffPointStyle()
- {
- grainCutOffPointStyleModel = XmlSerializeHelper.DESerializer<GrainCutOffPointStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainCutOffPointStyleModel.xml", FileMode.Open));
- // 0.5截点
- this.pointColor1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointColor;
- this.pointWidth1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointWidth;
- this.pointStyle1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointStyle;
- this.pointDiameter1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointDiameter;
- this.pointError1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointError;
- this.pointshape1 = grainCutOffPointStyleModel.CutOffPointStyle1.pointshape;
- // 1截点
- this.pointColor2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointColor;
- this.pointWidth2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointWidth;
- this.pointStyle2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointStyle;
- this.pointDiameter2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointDiameter;
- this.pointError2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointError;
- this.pointshape2 = grainCutOffPointStyleModel.CutOffPointStyle2.pointshape;
- // 1.5/2截点
- this.pointColor3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointColor;
- this.pointWidth3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointWidth;
- this.pointStyle3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointStyle;
- this.pointDiameter3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointDiameter;
- this.pointError3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointError;
- this.pointshape3 = grainCutOffPointStyleModel.CutOffPointStyle3.pointshape;
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 初始化矩形
- /// </summary>
- private void InitRectangleF(PointF pointF)
- {
- if (this.selectPicture)
- {
- // 圆形
- if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
- {
- foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
- {
- rectangleFLine = new RectangleF(pointF.X - this.lineDiameter / 2
- , pointF.Y - this.lineDiameter / 2, this.lineDiameter, this.lineDiameter);
- this.AddRectangleToRectangleFCaps();
- }
- }
- }
- // 矩形
- if (grainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
- {
- foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
- {
- rectangleFLine = new RectangleF(pointF.X - this.lineRectangleWidth / 2
- , pointF.Y - this.lineRectangleHeight / 2, this.lineRectangleWidth, this.lineRectangleHeight);
- this.AddRectangleToRectangleFCaps();
- }
- }
- }
- }
- }
- /// <summary>
- /// 刷新图形边线点集合
- /// </summary>
- private void AddRectangleToRectangleFCaps()
- {
- this.linePointList.Clear();
- // 圆形
- if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
- {
- foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
- {
- // 圆心
- Point center = new Point((int)(this.rectangleFLine.X + this.rectangleFLine.Width / 2), (int)(this.rectangleFLine.Y + this.rectangleFLine.Height / 2));
- for (int i = 0; i <= 360; i++)
- {
- OpenCvSharp.Point[] points = roundOutline(center, this.lineDiameter / 2);
- foreach (var point in points)
- {
- linePointList.Add(new Point(point.X, point.Y));
- }
- }
- }
- }
- }
- // 矩形
- if (grainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
- {
- foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
- {
- for (int l = (int)this.rectangleFLine.Y; l <= this.rectangleFLine.Bottom; l++)
- {
- if (this.rectangleFLine.X >= 0 && this.rectangleFLine.X < this.documentWorkspace.CompositionSurface.Width && l >= 0 && l < this.documentWorkspace.CompositionSurface.Height)
- linePointList.Add(new PointF(this.rectangleFLine.X, l));
- }
- for (int t = (int)this.rectangleFLine.X; t <= this.rectangleFLine.Right; t++)
- {
- if (t >= 0 && t < this.documentWorkspace.CompositionSurface.Width && this.rectangleFLine.Y >= 0 && this.rectangleFLine.Y < this.documentWorkspace.CompositionSurface.Height)
- linePointList.Add(new PointF(t, this.rectangleFLine.Y));
- }
- for (int r = (int)this.rectangleFLine.Y; r <= this.rectangleFLine.Bottom; r++)
- {
- if (this.rectangleFLine.Right >= 0 && this.rectangleFLine.Right < this.documentWorkspace.CompositionSurface.Width && r >= 0 && r < this.documentWorkspace.CompositionSurface.Height)
- linePointList.Add(new PointF(this.rectangleFLine.Right, r));
- }
- for (int t = (int)this.rectangleFLine.X; t <= this.rectangleFLine.Right; t++)
- {
- if (t >= 0 && t < this.documentWorkspace.CompositionSurface.Width && this.rectangleFLine.Bottom >= 0 && this.rectangleFLine.Bottom < this.documentWorkspace.CompositionSurface.Height)
- linePointList.Add(new PointF(t, this.rectangleFLine.Bottom));
- }
- }
- }
- }
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 更新辅助线及其样式
- /// </summary>
- private void UpdateGuideStyle()
- {
- // 圆形
- if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
- {
- foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
- {
- this.lineDiameter = circularGuideStyle.lineDiameter;
- this.lineColor = circularGuideStyle.lineColor;
- this.lineWidth = circularGuideStyle.lineWidth;
- }
- }
- }
- // 矩形
- if (grainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
- {
- foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
- {
- this.lineRectangleWidth = rectangleGuideStyle.lineRectangleWidth;
- this.lineRectangleHeight = rectangleGuideStyle.lineRectangleHeight;
- this.lineColor = rectangleGuideStyle.lineColor;
- this.lineWidth = rectangleGuideStyle.lineWidth;
- }
- }
- }
- }
- /// <summary>
- /// 辅助线维护
- /// </summary>
- public void InitComboboxValue(ArrayList arrayList)
- {
- grainSizeGuideAreaMethodModel = XmlSerializeHelper.DESerializer<GrainSizeGuideAreaMethodModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeGuideAreaMethodModel.xml", FileMode.Open));
- this.comboBox1.DataSource = null;
- if (arrayList != null && arrayList.Count > 0)
- {
- this.comboboxChange = false;
- this.comboBox1.DataSource = arrayList;
- this.comboboxChange = false;
- this.comboBox1.SelectedIndex = oldSelectIndex;
- }
- else
- {
- ArrayList arrayList1 = new ArrayList();
- // 圆形
- if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
- {
- foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
- {
- arrayList1.Add(circularGuideStyle.tag/*""*/);
- }
- }
- // 矩形
- if (grainSizeGuideAreaMethodModel.rectangleGuideStyles!= null)
- {
- foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
- {
- arrayList1.Add(rectangleGuideStyle.tag/*""*/);
- }
- }
- //// 圆形
- //if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
- //{
- // foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
- // {
- // arrayList1[circularGuideStyle.index - 1] = circularGuideStyle.tag;
- // }
- //}
- //// 矩形
- //if (grainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
- //{
- // foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
- // {
- // arrayList1[rectangleGuideStyle.index - 1] = rectangleGuideStyle.tag;
- // }
- //}
- this.comboBox1.DataSource = arrayList1;
- this.comboBox1.SelectedIndex = 0;
- }
- UpdateGuideStyle();
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// ListView图片选择改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void listView1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
- {
- existViewFlag = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList.IsExsitView();
- this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
- if (!existViewFlag)
- {
- mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
- }
- else
- {
- mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFullSizeWithRegion());
- }
- if (this.checkBox1.Checked)
- {
- this.applyDect();
- }
- //二值化相关
- Document document = Document.FromImage(bitmap);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Visible = true;
- this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList;
- this.applyButtonImpl(sender, e);
- this.histogramControl1.CreateHistogram(this.bitmap, true, 339, 130, 0);
- //二值化end
- this.selectPicture = true;
- this.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
- InitRectangleF(new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2));
- AddRectangleToRectangleFCaps();//#############
- }
- }
- /// <summary>
- /// 辅助线样式
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button9_Click(object sender, EventArgs e)
- {
- this.oldSelectIndex = this.comboBox1.SelectedIndex;
- GrainGuideStyleSettingsDialog grainGuideStyleSettingsDialog = new GrainGuideStyleSettingsDialog(1, this.gbtType);
- grainGuideStyleSettingsDialog.StartPosition = FormStartPosition.CenterScreen;
- grainGuideStyleSettingsDialog.ShowDialog(this);
- }
- /// <summary>
- /// 截点样式
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button10_Click(object sender, EventArgs e)
- {
- GrainSurveyPointStyleSettingDialog grainSurveyPointStyleSettingDialog = new GrainSurveyPointStyleSettingDialog();
- grainSurveyPointStyleSettingDialog.StartPosition = FormStartPosition.CenterScreen;
- grainSurveyPointStyleSettingDialog.ShowDialog(this);
- }
- /// <summary>
- /// 画布绘制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Panel_Paint(object sender, PaintEventArgs e)
- {
- if (this.documentWorkspace.CompositionSurface != null)
- {
- //
- // 以下是计算绘制图片的位置和大小并绘制图片
- //
- System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
- int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
- int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
- int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
- int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
- //
- // 以下是绘制网格、标注、测量、视场等开始
- //
- e.Graphics.TranslateTransform(x, y);
- e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
- if (this.checkBox4_0.Checked)
- Draw(e.Graphics);
- e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
- e.Graphics.TranslateTransform(-x, -y);
- }
- }
- /// <summary>
- /// 绘制
- /// </summary>
- private void Draw(Graphics graphics)
- {
- // 抗锯齿
- graphics.SmoothingMode = SmoothingMode.AntiAlias;
- Matrix mtxSave = graphics.Transform;
- Matrix matrix = graphics.Transform;
- // 以下为绘制样式
- Pen linePen = new Pen(Color.FromArgb(this.lineColor), this.lineWidth);
- Pen pointPen1 = new Pen(Color.Yellow, this.pointWidth1);
- Pen pointPen2 = new Pen(Color.FromArgb(this.pointColor2), this.pointWidth2);
- Pen pointPen3 = new Pen(Color.FromArgb(this.pointColor3), this.pointWidth3);
- SolidBrush brush1 = new SolidBrush(Color.FromArgb(this.pointColor1));
- SolidBrush brush2 = new SolidBrush(Color.FromArgb(this.pointColor2));
- SolidBrush brush3 = new SolidBrush(Color.FromArgb(this.pointColor3));
- // 圆形
- if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
- {
- foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
- {
- graphics.DrawEllipse(linePen, this.rectangleFLine.X, this.rectangleFLine.Y, this.rectangleFLine.Width, this.rectangleFLine.Height);
- }
- }
- }
- // 矩形
- if (grainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
- {
- foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
- {
- graphics.DrawRectangle(linePen, this.rectangleFLine.X, this.rectangleFLine.Y, this.rectangleFLine.Width, this.rectangleFLine.Height);
- }
- }
- }
- if (this.checkBox5_0.Checked && massLabelPoints.Count > 0)
- {
- int index = 0;
- Font myFont = new Font("宋体", 12/*, FontStyle.Bold*/);
- Brush bush = new SolidBrush(this.panel1.BackColor/*Color.Red*/);//填充的颜色
- foreach (var item in massLabelPoints)
- {
- graphics.DrawString("" + (++index), myFont, bush, (float)item.X - 5, (float)item.Y - 5);
- }
- }
- }
- /// <summary>
- /// 切换辅助线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.comboBox1.DataSource != null && this.comboBox1.SelectedIndex >= 0)
- {
- UpdateGuideStyle();
- if (this.selectPicture)
- {
- PointF pointF;
- if (this.comboboxChange)
- {
- pointF = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
- this.loctation = new PointF(this.documentWorkspace.CompositionSurface.Width / 2, this.documentWorkspace.CompositionSurface.Height / 2);
- }
- else
- pointF = this.loctation;
- InitRectangleF(pointF);
- this.comboboxChange = true;
- }
- this.documentWorkspace.Refresh();
- }
- }
- #region 矩形拖动
- /// <summary>
- /// 鼠标按下
- /// </summary>
- /// <param name="drawArea"></param>
- /// <param name="e"></param>
- private void OnMouseDown(object sender, MouseEventArgs e)
- {
- // 换算后的点
- PointF point1 = documentWorkspace.GetScalePoint(e.Location);
- foreach (var rectangleFCap in this.rectangleFCaps)
- {
- if (rectangleFCap.Contains(point1))
- {
- this.binarization = false;
- break;
- }
- }
- if (point1.X <= this.documentWorkspace.CompositionSurface.Width
- && point1.X >= 0
- && point1.Y >= 0
- && point1.Y <= this.documentWorkspace.CompositionSurface.Height)
- {
- if (e.Button == MouseButtons.Left && e.Clicks == 1)
- {
- // 0.5截点
- if (this.pointKb == 1)
- {
- }
- // 1截点
- else if (this.pointKb == 2)
- {
- if (this.rectangleFLine.Contains(point1))
- {
- double distance = 0;
- int init = 0;
- PointF pointFAdd = new PointF();
- foreach (var linePoint in this.linePointList)
- {
- double distance1 = BasicCalculationHelper.GetDistance(point1, linePoint, 10);
- if (init == 0)
- distance = distance1;
- else
- {
- if(distance1 < distance)
- {
- distance = distance1;
- pointFAdd = linePoint;
- }
- }
- init++;
- }
- this.binarization = false;
- if (pointStyle2 == 0)
- {
- this.rectangleFCaps.Add(new RectangleF(pointFAdd.X - this.pointDiameter2 / 2 - this.pointWidth2 / 2,
- pointFAdd.Y - this.pointDiameter2 / 2 - this.pointWidth2 / 2, this.pointDiameter2 + this.pointWidth2 * 2,
- this.pointDiameter2 + this.pointWidth2 * 2));
- }
- else
- {
- this.rectangleFCaps.Add(new RectangleF(pointFAdd.X - this.pointDiameter2 / 2, pointFAdd.Y - this.pointDiameter2 / 2,
- this.pointDiameter2, this.pointDiameter2));
- }
- }
- }
- // 1.5/2截点
- else if (this.pointKb == 3)
- {
- }
- }
- }
- if (e.Button == MouseButtons.Left && e.Clicks == 1)
- {
- if (this.rectangleFLine.Contains(point1))
- {
- this.binarization = false;
- m_canMove = true;
- this.m_StartPoint = point1;
- }
- }
- // 右键取消添加
- if (e.Button == MouseButtons.Right)
- {
- this.binarization = false;
- this.pointKb = 0;
- }
- if (e.Button == MouseButtons.Left && e.Clicks == 2)
- {
- this.binarization = false;
- foreach (var rectangleFCap in this.rectangleFCaps)
- {
- if (rectangleFCap.Contains(point1))
- {
- this.rectangleFCaps.Remove(rectangleFCap);
- break;
- }
- }
- }
- }
- /// <summary>
- /// 移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void onMouseMove(object sender, MouseEventArgs e)
- {
- // 换算后的点
- PointF point1 = documentWorkspace.GetScalePoint(e.Location);
- ox = e.X;
- oy = e.Y;
- y = (int)point1.Y;
- x = (int)point1.X;
- this.documentWorkspace.Refresh();
-
- if (e.Button == MouseButtons.Left && m_canMove)
- {
- if (this.pointKb == 2)
- {
- if(this.rectangleFCaps.Count > 0)
- this.rectangleFCaps.RemoveAt(this.rectangleFCaps.Count - 1);
- MessageBox.Show("当前为添加截点模式,若要移动图形请右键结束添加!");
- }
- else
- {
- // 矩形偏移
- rectangleFLine.Offset(point1.X - this.m_StartPoint.X, point1.Y - this.m_StartPoint.Y);
- this.loctation = new PointF(this.rectangleFLine.X + this.rectangleFLine.Width / 2, this.rectangleFLine.Y + this.rectangleFLine.Height / 2);
- this.m_StartPoint = point1;
- this.AddRectangleToRectangleFCaps();
- this.documentWorkspace.Refresh();
- }
- }
- }
- /// <summary>
- /// 鼠标抬起
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void onMouseUp(object sender, MouseEventArgs e)
- {
- this.binarization = true;
- m_canMove = false;
- this.AddRectangleToRectangleFCaps();
- }
- #endregion
- /// <summary>
- /// surfaceBox双击事件
- /// 目前是参考AxioVision
- /// 应该是把每次选的点都取最高和最低的BGR
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private unsafe void pictureBox1_Click(object sender, EventArgs e)
- {
- if (this.binarization)
- {
- }
- }
- /// <summary>
- /// 移除未完成的定义物体的轮廓的对象
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void GrainSizeDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- this.documentWorkspace.GraphicsList.DeleteDrawClass(DrawClass.PhaseExtraction);
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 是否显示晶粒编号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox5_0_CheckedChanged(object sender, EventArgs e)
- {
- //if (!this.checkBox4_0.Checked)
- // MessageBox.Show("没有网格!");
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 是否显示网格
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox4_0_CheckedChanged(object sender, EventArgs e)
- {
- this.documentWorkspace.Refresh();
- }
- #region 二值化相关
- /// <summary>
- /// 添加参数改变的监听
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void GrainSizeDialog_Load(object sender, EventArgs e)
- {
- this.comboBox3.Text = "请选择去噪类型";
- this.comboBox3.SelectedIndex = 1;
- this.comboBox2.Text = "请选择晶界类型";
- this.comboBox2.SelectedIndex = 1;
- foreach (Args args in action.Lists)
- {
- switch (args.Key)
- {
- case "colorInterval"://颜色区间
- button6.Click += new EventHandler(this.applyButtonImpl);
- break;
- case "scope1"://不反选时候的范围
- numberScopeControl1.ValueChanged += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
- break;
- case "scope2"://反选时候的范围1
- numberScopeControl2.ValueChanged += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
- break;
- case "scope3"://反选时候的范围2
- numberScopeControl3.ValueChanged += new EventHandler(((DecimalScope)args).numberScope_ValueChanged);
- break;
- case "autoThreshold"://自动阈值
- button7.Click += new EventHandler(this.applyButtonImpl);
- break;
- case "phaseColor":
- args.Value = this.binaryExtractionModel.PhaseColor;
- break;
- default:
- break;
- }
- }
- }
- /// <summary>
- /// 参数改变时,重新处理图像
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void applyButtonImpl(object sender, EventArgs e)
- {
- long start = Cv2.GetTickCount();
- if (this.listView1.FocusedItem != null && checkBox10.Checked)
- {
- //判断是否存在视场,如果存在视场,则把视场提取出来,进行处理
- if (this.documentWorkspace.GraphicsList.IsExsitView())
- {
- this.documentWorkspace.PhaseModels[0].mat = action.PerformProcess(
- OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.GetFullSizeWithRegion()),
- OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- this.documentWorkspace.PhaseModels[0].color = this.panel2.BackColor.ToArgb();
- this.documentWorkspace.Refresh();
- }
- else
- {
- this.documentWorkspace.PhaseModels[0].mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- this.documentWorkspace.PhaseModels[0].color = this.panel2.BackColor.ToArgb();
- this.documentWorkspace.Refresh();
- }
- }
- double time = (Cv2.GetTickCount() - start) / Cv2.GetTickFrequency();
- System.Console.WriteLine("执行时间:" + time);
- }
- /// <summary>
- /// 反选/取消反选
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button6_Click(object sender, EventArgs e)
- {
- if (numberScopeControl2.Visible)
- {
- this.numberScopeControl1.minValue = this.numberScopeControl3.maxValue;
- this.numberScopeControl1.maxValue = this.numberScopeControl2.minValue;
- this.numberScopeControl2.Visible = false;
- this.numberScopeControl3.Visible = false;
- this.button6.Text = "反选";
- this.binaryExtractionModel.ColorInterval = 1;
- this.histogramControl1.Flag = 1;
- this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue));
- }
- else
- {
- this.numberScopeControl3.minValue = 0;
- this.numberScopeControl3.maxValue = this.numberScopeControl1.minValue;
- this.numberScopeControl2.minValue = this.numberScopeControl1.maxValue;
- this.numberScopeControl2.maxValue = 255;
- this.numberScopeControl2.Visible = true;
- this.numberScopeControl3.Visible = true;
- this.button6.Text = "取消反选";
- this.binaryExtractionModel.ColorInterval = 2;
- this.histogramControl1.Flag = 2;
- //处理直方图
- this.histogramControl1.UpdateVerticalBarWithTwoScope(
- (int)(this.numberScopeControl3.minValue),
- (int)(this.numberScopeControl3.maxValue),
- (int)(this.numberScopeControl2.minValue),
- (int)(this.numberScopeControl2.maxValue)
- );
- }
- foreach (Args args in action.Lists)
- {
- if (args.Key == "colorInterval")
- {
- args.Value = this.binaryExtractionModel.ColorInterval;
- break;
- }
- else if (args.Key == "scope1")
- {
- List<double> twoL = new List<double>();
- twoL.Add(this.numberScopeControl1.minValue);
- twoL.Add(this.numberScopeControl1.maxValue);
- args.Value = twoL;
- }
- else if (args.Key == "scope2")
- {
- List<double> twoL = new List<double>();
- twoL.Add(this.numberScopeControl3.minValue);
- twoL.Add(this.numberScopeControl3.maxValue);
- args.Value = twoL;
- }
- else if (args.Key == "scope3")
- {
- List<double> twoL = new List<double>();
- twoL.Add(this.numberScopeControl2.minValue);
- twoL.Add(this.numberScopeControl2.maxValue);
- args.Value = twoL;
- }
- }
- }
- /// <summary>
- /// 一个颜色区间时
- /// 区间值变化的事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numberScope1_ValueChanged(object sender, EventArgs e)
- {
- //参数改变
- foreach (Args args in action.Lists)
- {
- if (args.Key == "scope1")
- {
- ((List<double>)args.Value)[0] = (int)this.numberScopeControl1.numericUpDown1.Value;
- ((List<double>)args.Value)[1] = (int)this.numberScopeControl1.numericUpDown2.Value;
- break;
- }
- }
- this.binaryExtractionModel.ColorOneStart = (int)(this.numberScopeControl1.numericUpDown1.Value);
- this.binaryExtractionModel.ColorOneEnd = (int)(this.numberScopeControl1.numericUpDown2.Value);
- //处理直方图
- this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue));
- }
- /// <summary>
- /// 二个颜色区间时
- /// 区间1值变化的事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numberScope2_ValueChanged(object sender, EventArgs e)
- {
- //参数改变
- foreach (Args args in action.Lists)
- {
- if (args.Key == "scope2")
- {
- ((List<double>)args.Value)[0] = (int)this.numberScopeControl2.numericUpDown1.Value;
- ((List<double>)args.Value)[1] = (int)this.numberScopeControl2.numericUpDown2.Value;
- break;
- }
- }
- this.binaryExtractionModel.ColorTwoStart = (int)(this.numberScopeControl2.minValue);
- this.binaryExtractionModel.ColorTwoEnd = (int)(this.numberScopeControl2.maxValue);
- //处理直方图
- this.histogramControl1.UpdateVerticalBarWithTwoScope(
- (int)(this.numberScopeControl3.minValue),
- (int)(this.numberScopeControl3.maxValue),
- (int)(this.numberScopeControl2.minValue),
- (int)(this.numberScopeControl2.maxValue)
- );
- }
- /// <summary>
- /// 二个颜色区间时
- /// 区间2值变化的事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numberScope3_ValueChanged(object sender, EventArgs e)
- {
- //参数改变
- foreach (Args args in action.Lists)
- {
- if (args.Key == "scope3")
- {
- ((List<double>)args.Value)[0] = (int)this.numberScopeControl3.numericUpDown1.Value;
- ((List<double>)args.Value)[1] = (int)this.numberScopeControl3.numericUpDown2.Value;
- break;
- }
- }
- this.binaryExtractionModel.ColorThreeStart = (int)(this.numberScopeControl3.minValue);
- this.binaryExtractionModel.ColorThreeEnd = (int)(this.numberScopeControl3.maxValue);
- //处理直方图
- this.histogramControl1.UpdateVerticalBarWithTwoScope(
- (int)(this.numberScopeControl3.minValue),
- (int)(this.numberScopeControl3.maxValue),
- (int)(this.numberScopeControl2.minValue),
- (int)(this.numberScopeControl2.maxValue)
- );
- }
- /// <summary>
- /// 自动阈值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button7_Click(object sender, EventArgs e)
- {
- if (bitmap != null)
- {
- //先计算阈值
- Mat mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
- Mat gray = mat.CvtColor(ColorConversionCodes.BGR2GRAY);
- double otsu = Cv2.Threshold(gray, gray, 0, 255, ThresholdTypes.Otsu);
- //如果当前是两个区间,则需要重新计算一次
- if (this.binaryExtractionModel.ColorInterval == 2)
- {
- this.button6.PerformClick();
- }
- else
- {
- //隐藏控件
- this.numberScopeControl2.Visible = false;
- this.numberScopeControl3.Visible = false;
- this.button6.Text = "反选";
- }
- //给控件赋值
- this.numberScopeControl1.minValue = 0;
- this.numberScopeControl1.maxValue = otsu;
- //处理直方图
- this.histogramControl1.UpdateVerticalBarWithOneScope(0, Convert.ToInt32(this.numberScopeControl1.maxValue));
- mat.Dispose();
- GC.Collect();
- }
- else
- {
- MessageBox.Show("请先选择图片");
- }
- }
- /// <summary>
- /// 显示原图/原图+二值图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ShowOrHideOriginPic(object sender, EventArgs e)
- {
- if (!checkBox5.Checked)
- {
- if (checkBox10.Checked)
- this.documentWorkspace.PhaseModels[0].choise = true;
- if (checkBox3_0.Checked)
- this.documentWorkspace.PhaseModels[1].choise = true;
- if (checkBox11.Checked)
- this.documentWorkspace.PhaseModels[2].choise = true;
- }
- else
- {
- this.documentWorkspace.PhaseModels[0].choise = false;
- this.documentWorkspace.PhaseModels[1].choise = false;
- }
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 二值样式 实心选中事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- //参数改变
- foreach (Args args in action.Lists)
- {
- if (args.Key == "binaryStyle")
- {
- if (radioButton1.Checked)
- {
- args.Value = 1;
- }
- else
- {
- args.Value = 2;
- }
- break;
- }
- }
- this.binaryExtractionModel.BinaryStyle = radioButton1.Checked ? 1 : 2;
- }
- /// <summary>
- /// 二值样式 边线选中事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void radioButton2_CheckedChanged(object sender, EventArgs e)
- {
- //参数改变
- foreach (Args args in action.Lists)
- {
- if (args.Key == "binaryStyle")
- {
- if (radioButton1.Checked)
- {
- args.Value = 1;
- }
- else
- {
- args.Value = 2;
- }
- break;
- }
- }
- this.binaryExtractionModel.BinaryStyle = radioButton1.Checked ? 1 : 2;
- }
- private void panel1_Click(object sender, EventArgs e)
- {
- this.currentPanel = 1;
- this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
- this.colorsFormGrid.ShowDialog();
- }
- /// <summary>
- /// 相颜色点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel2_Click(object sender, EventArgs e)
- {
- this.currentPanel = 2;
- this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor);
- this.colorsFormGrid.ShowDialog();
- }
- /// <summary>
- /// Panel2的调色板颜色改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gridColorChanged(object sender, EventArgs e)
- {
- Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
- //先修改参数
- foreach (Args args in action.Lists)
- {
- if (args.Key == "phaseColor")
- {
- args.Value = color.ToArgb();
- break;
- }
- }
- //更改背景色,触发事件
- if (this.currentPanel == 1)
- {
- this.panel1.BackColor = color;
- this.documentWorkspace.Refresh();
- }
- else if (this.currentPanel == 1)
- {
- this.panel2.BackColor = color;
- //改变配置文件里面的相颜色
- this.binaryExtractionModel.PhaseColor = color.ToArgb();
- }
- //关闭色板
- this.colorsFormGrid.Close();
- }
- private void checkBox10_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox10.Checked && !checkBox5.Checked)
- {
- this.documentWorkspace.PhaseModels[0].choise = true;
- }
- else
- {
- this.documentWorkspace.PhaseModels[0].choise = false;
- }
- this.documentWorkspace.Refresh();
- }
- #endregion
- /// <summary>
- /// 保存结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- if (this.listView1.SelectedItems.Count > 0)
- {
- if(this.comboBox1.SelectedItem != null)
- {
- string imgName = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
- string tag = this.imageList1.Images.Keys[this.listView1.SelectedItems[0].Index];
- System.Data.DataTable dataTable = new System.Data.DataTable();
- bool replace = false;
- int add = 0;
- foreach (ListViewItem item in this.listView2.Items)
- {
- if (item.Tag.Equals(tag))
- {
- add++;
- DialogResult dr = MessageBox.Show("结果已存在,是否替换?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr == DialogResult.OK)
- {
- replace = true;
- }
- break;
- }
- }
- if (replace || this.listView2.Items.Count == 0 || add == 0)
- {
- if (!replace)
- {
- ListViewItem listViewItem = new ListViewItem();
- listViewItem.SubItems[0].Text = imgName;
- listViewItem.Tag = "" + tag;
- if (this.listView2.Items.Count == 0)
- this.listView2.Items.Add(listViewItem);
- else
- this.listView2.Items.Insert(0, listViewItem);
- }
- this.dataGridView4.Rows.Clear();
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn c in this.dataGridView4.Columns)
- {
- dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
- }
- dgvr.Cells[0].Value = imgName;
- dgvr.Cells[1].Value = this.comboBox1.SelectedItem;
- double aec = 0;
- // 圆形
- if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
- {
- foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
- {
- dgvr.Cells[2].Value = this.lineDiameter / 2 * this.lineDiameter / 2 * Math.PI;
- aec = this.lineDiameter / 2 * this.lineDiameter / 2 * Math.PI;
- }
- }
- }
- // 矩形
- if (grainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
- {
- foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
- {
- dgvr.Cells[2].Value = this.lineRectangleWidth * this.lineRectangleHeight;
- aec = this.lineRectangleWidth * this.lineRectangleHeight;
- }
- }
- }
- double grainNumber = GetNumberOfGrains(linePointList, rectangleFLine);
- dgvr.Cells[3].Value = grainNumber;
- decimal M = this.appWorkspace.GetGainMultiple() ;
- double NA = (double)M * (double)M * grainNumber / aec;
- double G = 3.321928 * Math.Log10(NA) - 2.954;
- dgvr.Cells[4].Value = G;
- this.dataGridView4.Rows.Add(dgvr);
- dataTable.TableName = tag;
- foreach (System.Data.DataTable dataTable1 in dataTables)
- {
- if (dataTable1.TableName.Equals(dataTable.TableName))
- {
- dataTables.Remove(dataTable1);
- break;
- }
- }
- foreach (DataGridViewColumn c in this.dataGridView4.Columns)
- {
- dataTable.Columns.Add(c.HeaderText);
- }
- for (int r = 0; r < this.dataGridView4.Rows.Count; r++)
- {
- DataRow dataRow = dataTable.NewRow();
- for (int c = 0; c < this.dataGridView4.Rows[r].Cells.Count; c++)
- {
- dataRow[this.dataGridView4.Columns[c].HeaderText] = this.dataGridView4.Rows[r].Cells[c].Value;
- }
- dataTable.Rows.Add(dataRow);
- }
- this.dataTables.Add(dataTable);
-
- //保存处理后的图片
- List<Bitmap> tempBit = new List<Bitmap>();
- Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
- tempBit.Add(originalBit);
- Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
- Graphics graphics = Graphics.FromImage(newBit);
- Draw(graphics);
- tempBit.Add(newBit);
- if (bitDic.ContainsKey(tag))
- bitDic[tag] = tempBit;
- else
- bitDic.Add(tag, tempBit);
- }
- }
- else
- {
- MessageBox.Show("请选择辅助线!");
- }
- }
- else
- {
- MessageBox.Show("请选择图片!");
- }
-
- }
- /// <summary>
- /// 切换分析结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void listView2_SelectedIndexChanged(object sender, EventArgs e)
- {
- if(!this.allShow)
- {
- if(this.listView2.SelectedItems.Count > 0)
- {
- System.Data.DataTable dataTable1 = new System.Data.DataTable();
- foreach (var dataTable in this.dataTables)
- {
- if (this.listView2.SelectedItems[0].Tag.Equals(dataTable.TableName))
- dataTable1 = dataTable;
- }
- this.dataGridView4.Rows.Clear();
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- for (int c = 0; c < dataTable1.Columns.Count; c++)
- {
- dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
- }
- this.dataGridView4.Rows.Add(dgvr);
- }
- }
- }
- /// <summary>
- /// 晶界重现
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- if (this.checkBox1.Checked && !checkBox5.Checked && checkBox3_0.Checked)
- {
- this.documentWorkspace.PhaseModels[1].choise = true;
- }
- else
- {
- this.documentWorkspace.PhaseModels[1].choise = false;
- this.documentWorkspace.Refresh();
- }
- if (this.checkBox1.Checked)
- {
- this.applyDect();
- }
- }
- private void applyDect()
- {
- if (this.bitmap == null)
- {
- return;
- }
- double sigma = 0.5;
- if (!double.TryParse(textBox6.Text, out sigma))
- {
- return;
- }
- //string inputImageFile = "原始图片1.jpg";// "j1.JPG";
- ////char[] inputImageFile2 = inputImageFile.ToCharArray();
- Mat OrgImg = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);// OpenCvSharp.Cv2.ImRead(inputImageFile);
- int dark = this.comboBox2.SelectedIndex;// 2;//指定晶界类型,暗晶界dark=1, 否则dark=0, dark=2梯度
- int smooth_type = this.comboBox3.SelectedIndex;// 1;//去噪类型: 高斯平滑: smooth_type=0; 方向平滑: smooth_type=1
- //double sigma = double.Parse(textBox6.Text);// 0.5;//如果是高斯平滑,则指定高斯sigma,如果是方向平滑 则忽略此参数
- int enhance = this.checkBox2.Checked ? 1 : 0;// 1;//是否增强晶界?不增强:enhance=0; 增强: enhance=1
- double[] cell_size = new double[2] { (double)numericUpDown1.Value, (double)numericUpDown2.Value }; ;// new double[2] { 0.01, 500 };//晶界大小
- this.runDect(OrgImg, dark, smooth_type, sigma, enhance, cell_size);
- }
- private Mat runDect(Mat OrgImg0, int dark, int smooth_type, double sigma, int enhance, double[] cell_size)
- {
- Mat GryImg = new Mat();
- Mat OrgImg = new Mat();
- /////
- if (4 == OrgImg0.Channels())
- {
- Cv2.CvtColor(OrgImg0, OrgImg, ColorConversionCodes.BGRA2BGR);
- }
- else
- {
- OrgImg = OrgImg0.Clone();
- }
- In5segmsurf prm = new In5segmsurf();
- prm.OrgImg = OrgImg;
- /////
- //Cv2.ImShow("src", OrgImg);//kkkkk
- //Cv2.WaitKey(0);//kkkkk
- //转为为灰度?
- if (3 == OrgImg.Channels() || 4 == OrgImg.Channels())
- {
- Cv2.CvtColor(OrgImg, GryImg, ColorConversionCodes.RGB2GRAY);
- }
- else
- {
- if (1 == OrgImg.Channels())
- {
- GryImg = OrgImg.Clone();
- }
- else
- {
- return null;
- }
- }
- if (1 == dark)
- {
- int Rows = GryImg.Rows;
- int Cols = GryImg.Cols;
- int[] point = new int[2];
- //单通道图像的反色
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- byte bTemp = (byte)(255 - GryImg.At<byte>(point[0], point[1]));
- GryImg.Set<byte>(point, bTemp);//mmmmm
- }
- }
- }
- if (2 == dark)
- {
- Mat TempImg = GryImg.Clone();
- Cv2.Sobel(TempImg, GryImg, -1, 2, 2, 3);//mmmmm
- }
- //Cv2.ImShow("src", GryImg);//kkkkk
- //Cv2.WaitKey(0);//kkkkk
- //去噪
- if (0 == smooth_type)
- {
- prm.smoothim_method = "gaussian";
- }
- else
- {
- if (1 == smooth_type)
- {
- prm.smoothim_method = "dirced";
- }
- else
- {
- return null;
- }
- }
- //晶界增强
- if (1 == enhance)
- {
- prm.filterridges = 1;
- }
- else
- {
- prm.filterridges = 0;
- }
- //调用算法
- prm.gaussian_stdev = sigma;
- prm.LEVEL = ".3";
- prm.classifycells_convexarea = 0.50;
- prm.classifycells_convexperim = 0.45;
- OLDcellsegm cellsegm = new OLDcellsegm();
- string[] namehere = new string[1] { "prm" };
- In6segmsurf IN6BNImgs = new In6segmsurf();
- OUTsegmsurf RSTss = cellsegm.mf_segmsurf(GryImg, cell_size[0], cell_size[1], namehere, prm, IN6BNImgs);
- cell_size = null;
- cellsegm = null;
- namehere = null;
- Cv2.CvtColor(RSTss.wat, OrgImg0, ColorConversionCodes.BGR2BGRA);
- this.documentWorkspace.PhaseModels[1].mat = OrgImg0;// RSTss.wat;// action.PerformProcess(
- // OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.GetFullSizeWithRegion()),
- // OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- ////this.documentWorkspace.PhaseModels[1].color = this.panel2.BackColor.ToArgb();
- this.documentWorkspace.Refresh();
- //return RSTss.wat;
- //string filename = "D:\\result11.jpg";
- //Cv2.ImWrite(filename, RSTss.wat);
- return null;
- }
- private void checkBox3_0_CheckedChanged(object sender, EventArgs e)
- {
- if (!checkBox5.Checked && checkBox3_0.Checked)
- {
- this.documentWorkspace.PhaseModels[1].choise = true;
- }
- else
- {
- this.documentWorkspace.PhaseModels[1].choise = false;
- }
- this.documentWorkspace.Refresh();
- }
- private void checkBox2_CheckedChanged(object sender, EventArgs e)
- {
- if (this.checkBox1.Checked)
- {
- this.applyDect();
- }
- }
- private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.checkBox1.Checked)
- {
- this.applyDect();
- }
- }
- private void textBox6_TextChanged(object sender, EventArgs e)
- {
- if (this.checkBox1.Checked)
- {
- this.applyDect();
- }
- }
- private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.checkBox1.Checked)
- {
- this.applyDect();
- }
- }
- private void numericUpDown1_ValueChanged_1(object sender, EventArgs e)
- {
- if (this.checkBox1.Checked)
- {
- this.applyDect();
- }
- }
- private void numericUpDown2_ValueChanged_1(object sender, EventArgs e)
- {
- if (this.checkBox1.Checked)
- {
- this.applyDect();
- }
- }
- /// <summary>
- /// 用不同颜色显示晶粒
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void checkBox11_CheckedChanged(object sender, EventArgs e)
- {
- if (!checkBox5.Checked && checkBox11.Checked)
- {
- this.documentWorkspace.PhaseModels[2].choise = true;
- }
- else
- {
- this.documentWorkspace.PhaseModels[2].choise = false;
- }
- this.documentWorkspace.Refresh();
- }
- /// <summary>
- /// 设置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- //Template.Manager.item3.GrainSizeArea1Method######001
- AnalyzeSettingDialog metallographicMethodSetDialog = new AnalyzeSettingDialog(this, "Template.Manager.item3.GrainSizeArea1Method");//#############001
- if (metallographicMethodSetDialog.hasModule)
- {
- metallographicMethodSetDialog.StartPosition = FormStartPosition.CenterScreen;
- metallographicMethodSetDialog.ShowDialog();
- }
- else
- {
- metallographicMethodSetDialog = null;
- }
- }
- /// <summary>
- /// 导出结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button14_Click(object sender, EventArgs e)
- {
- if (this.listView2.Items.Count > 0)
- {
- SaveFileDialog exe = new SaveFileDialog();
- exe.Filter = "Execl files (*.xls)|*.xls";
- exe.FilterIndex = 0;
- exe.RestoreDirectory = true;
- //exe.CreatePrompt = true;
- exe.Title = "Export Excel File";
- exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- exe.FileName = "晶粒度(面积法)分析结果" + DateTime.Now.ToString("yyyyMMddHHmmss");
- DialogResult dr = exe.ShowDialog();
- if (dr != DialogResult.OK)
- {
- return;
- }
- DataTable dtb = new DataTable();
- foreach (var item in this.contentHead)
- {
- dtb.Columns.Add(item);
- }
- for (int i = 0; i < this.dataGridView4.Rows.Count; i++)
- {
- DataRow dataRow = dtb.NewRow();
- for (int k = 0; k < this.contentHead.Count; k++)
- {
- dataRow[this.contentHead[k]] = this.dataGridView4.Rows[i].Cells[k].Value;
- }
- dtb.Rows.Add(dataRow);
- }
- Stream ms;
- ms = exe.OpenFile();
- StreamWriter sw = new StreamWriter(ms, System.Text.Encoding.GetEncoding(-0));
- string str = "";
- try
- {
- for (int i = 0; i < dtb.Columns.Count; i++)
- {
- if (i > 0)
- {
- str += "\t";
- }
- str += dtb.Columns[i].ColumnName;
- }
- sw.WriteLine(str);
- for (int j = 0; j < dtb.Rows.Count; j++)
- {
- string temp = "";
- for (int k = 0; k < dtb.Columns.Count; k++)
- {
- if (k > 0)
- {
- temp += "\t";
- }
- string cell = dtb.Rows[j][k].ToString();
- cell = cell.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\r\n", "");
- temp += cell;
- }
- sw.WriteLine(temp);
- }
- sw.Close();
- ms.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- return;
- }
- finally
- {
- sw.Close();
- ms.Close();
- }
- }
- else
- MessageBox.Show("没有分析结果,无法生成报告!");
- }
- /// <summary>
- /// 生成报告
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button13_Click(object sender, EventArgs e)
- {
- if (this.checkBox2_0.Checked)
- this.button1.PerformClick();
- if (this.analyzeSettingModel != null && !string.IsNullOrEmpty(this.analyzeSettingModel.analyzeClassify))
- {
- //获取word书签与excel单元格的关系,以字典方式存储
- List<mic_module_infos> mic_module_infos = PaintDotNet.DbOpreate.DbBll.mic_module_infos_BLL.FindAll().FindAll(a => a.analyze_classify == this.analyzeSettingModel.analyzeClassify);
- Dictionary<string, string> tagInfos = new Dictionary<string, string>();
- if (mic_module_infos != null && mic_module_infos.Count > 0)
- {
- foreach (mic_module_infos info in mic_module_infos)
- {
- tagInfos.Add(info.tag_name, info.cell_position);
- }
- }
- //分析结果
- List<List<string>> analysisContent = new List<List<string>>();
- analysisContent.Add(contentHead);
- foreach (DataGridViewRow item in this.dataGridView4.Rows)
- {
- List<string> content = new List<string>();
- for (int i = 0; i < contentHead.Count; i++)
- {
- content.Add(item.Cells[i].Value.ToString());
- }
- analysisContent.Add(content);
- }
- //图片
- bitList = new List<Bitmap>();
- if (this.allShow)
- {
- foreach (KeyValuePair<string, List<Bitmap>> kv in this.bitDic)
- {
- bitList.Add(kv.Value[0]);
- bitList.Add(kv.Value[1]);
- }
- }
- else
- {
- if (this.listView2.SelectedItems != null && this.listView2.SelectedItems.Count > 0)
- {
- foreach (ListViewItem item in this.listView2.SelectedItems)
- {
- if (bitDic.ContainsKey(item.Name))
- {
- bitList.Add(bitDic[item.Name][0]);
- bitList.Add(bitDic[item.Name][1]);
- }
- else if (bitDic.ContainsKey(item.Tag.ToString()))
- {
- bitList.Add(bitDic[item.Tag.ToString()][0]);
- bitList.Add(bitDic[item.Tag.ToString()][1]);
- }
- }
- }
- else if (this.listView2.Items.Count > 0)//###
- {
- ListViewItem item = this.listView2.Items[0];
- if (bitDic.ContainsKey(item.Name))
- {
- bitList.Add(bitDic[item.Name][0]);
- bitList.Add(bitDic[item.Name][1]);
- }
- else if (bitDic.ContainsKey(item.Tag.ToString()))
- {
- bitList.Add(bitDic[item.Tag.ToString()][0]);
- bitList.Add(bitDic[item.Tag.ToString()][1]);
- }
- }
- }
- OfficeFileHandleHelper.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos);
- }
- else
- MessageBox.Show("请先对分析报告进行设置!");
- }
- /// <summary>
- /// 晶界编辑
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- if (/*this.documentWorkspace.PhaseModels[1].choise == true && */this.documentWorkspace.PhaseModels[1].mat == null)
- {
- MessageBox.Show("请先进行晶界重现操作");
- return;
- }
- }
- /// <summary>
- /// 全部显示
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button11_Click(object sender, EventArgs e)
- {
- if (this.listView2.Items.Count > 0)
- {
- this.button11.Visible = false;
- this.button16.Visible = true;
- this.button16.Focus();
- this.allShow = true;
- this.dataGridView4.Rows.Clear();
- for (int i = 0; i < this.dataTables.Count; i++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- for (int c = 0; c < this.dataTables[i].Columns.Count; c++)
- {
- dgvr.Cells[c].Value = this.dataTables[i].Rows[0][c].ToString();
- }
- this.dataGridView4.Rows.Add(dgvr);
- }
- }
- else
- {
- MessageBox.Show("没有数据!");
- }
- }
- /// <summary>
- /// 取消全部显示
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button16_Click(object sender, EventArgs e)
- {
- this.button11.Visible = true;
- this.button16.Visible = false;
- this.button11.Focus();
- this.allShow = false;
- System.Data.DataTable dataTable1 = new System.Data.DataTable();
- foreach (var dataTable in this.dataTables)
- {
- if (this.listView2.SelectedItems.Count > 0)
- {
- if (this.listView2.SelectedItems[0].Tag.Equals(dataTable.TableName))
- dataTable1 = dataTable;
- }
- else
- {
- if (this.listView2.Items[0].Tag.Equals(dataTable.TableName))
- dataTable1 = dataTable;
- }
- }
- this.dataGridView4.Rows.Clear();
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- for (int c = 0; c < dataTable1.Columns.Count; c++)
- {
- dgvr.Cells[c].Value = dataTable1.Rows[0][c].ToString();
- }
- this.dataGridView4.Rows.Add(dgvr);
- }
- /// <summary>
- /// 分析结果删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button12_Click(object sender, EventArgs e)
- {
- if(this.listView2.Items.Count > 0)
- {
- if(this.listView2.SelectedItems.Count > 0)
- {
- DialogResult dr = MessageBox.Show("确认删除选中的数据吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr == DialogResult.OK)
- {
- int selectIndex = this.listView2.SelectedItems[0].Index;
- foreach (var dataTable in this.dataTables)
- {
- if (dataTable.TableName.Equals(this.listView2.SelectedItems[0].Tag))
- {
- this.dataTables.Remove(dataTable);
- break;
- }
- }
- this.listView2.Items.RemoveAt(selectIndex);
- if (this.listView2.Items.Count == 0)
- this.dataGridView4.Rows.Clear();
- else
- {
- if (selectIndex == 0)
- this.listView2.Items[0].Selected = true;
- else
- this.listView2.Items[selectIndex - 1].Selected = true;
- RefreshDataGridView4();
- }
- }
- }
- else
- {
- MessageBox.Show("请选择要删除的数据!");
- }
- }
- else
- {
- MessageBox.Show("没有数据!");
- }
- }
- /// <summary>
- /// 刷新分析结果数据
- /// </summary>
- private void RefreshDataGridView4()
- {
- if (!this.allShow)
- {
- if (this.listView2.SelectedItems.Count > 0)
- {
- int dataTableIndex = 0;
- for (int i = 0; i < this.dataTables.Count; i++)
- {
- if (this.dataTables[i].TableName.Equals(this.listView2.SelectedItems[0].Tag))
- dataTableIndex = i;
- }
- if (this.dataTables[dataTableIndex].Rows.Count > 0)
- {
- this.dataGridView4.Rows.Clear();
- for (int r = 0; r < this.dataTables[dataTableIndex].Rows.Count; r++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- for (int c = 0; c < this.dataTables[dataTableIndex].Columns.Count; c++)
- {
- dgvr.Cells[c].Value = this.dataTables[dataTableIndex].Rows[r][c].ToString();
- }
- this.dataGridView4.Rows.Add(dgvr);
- }
- }
- }
- }
- else
- {
- this.dataGridView4.Rows.Clear();
- DataTable dataTable = new DataTable();
- for (int i = this.dataTables.Count - 1; i >= 0; i--)
- {
- dataTable = this.dataTables[i];
- for (int r = 0; r < dataTable.Rows.Count; r++)
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- foreach (DataGridViewColumn Column in this.dataGridView4.Columns)
- {
- dgvr.Cells.Add(Column.CellTemplate.Clone() as DataGridViewCell);
- }
- for (int c = 0; c < dataTable.Columns.Count; c++)
- {
- dgvr.Cells[c].Value = dataTable.Rows[r][c].ToString();
- }
- this.dataGridView4.Rows.Add(dgvr);
- }
- }
- }
- }
- /// <summary>
- /// 小数位数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void numericUpDown1_0_ValueChanged(object sender, EventArgs e)
- {
- //this.dec = Convert.ToInt32(this.numericUpDown1.Value);
- //if(this.dataTables.Count > 0)
- //{
- // foreach (var dataTable in this.dataTables)
- // {
- // }
- //}
- }
- private Double GetNumberOfGrains(List<PointF> pointFs, RectangleF rectangleF)
- {
- Mat OriginalPicture;// = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- if (this.checkBox1.Checked && this.documentWorkspace.PhaseModels[1].mat != null)
- {
- OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- Mat oldMat = this.documentWorkspace.PhaseModels[1].mat;
- int Rows = oldMat.Rows;
- int Cols = oldMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (oldMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- {
- OriginalPicture.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
- }
- }
- }
- Cv2.Erode(OriginalPicture, OriginalPicture, null, null, 1);
- }
- else if (this.checkBox10.Checked && this.documentWorkspace.PhaseModels[0].mat != null)
- {
- OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- Mat oldMat = this.documentWorkspace.PhaseModels[0].mat;
- int Rows = oldMat.Rows;
- int Cols = oldMat.Cols;
- int[] point = new int[2];
- //多通道图像的格式化
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (oldMat.At<Vec4b>(point[0], point[1]).Item3 > 0)
- {
- OriginalPicture.Set<Vec4b>(point, new Vec4b(0, 0, 0, 255));
- }
- }
- }
- }
- else
- {
- OriginalPicture = new Mat(mat.Size(), MatType.CV_8UC4, new Scalar(255, 255, 255, 255));
- mat.CopyTo(OriginalPicture);
- }
- Mat erzhi = OriginalPicture;
- Cv2.CvtColor(erzhi, erzhi, ColorConversionCodes.BGR2GRAY);
- Cv2.Threshold(erzhi, erzhi, 100, 255, ThresholdTypes.Binary);//#############
- //Cv2.AdaptiveThreshold(erzhi, erzhi, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 99, 10);
- OpenCvSharp.Point[][] contours;
- HierarchyIndex[] hierarchy;
- Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
- //Cv2.ImWrite("erzhi1.tif", erzhi.CvtColor(ColorConversionCodes.GRAY2BGR));
- List<OpenCvSharp.Point[]> pointss = new List<OpenCvSharp.Point[]>();
- foreach (OpenCvSharp.Point[] contour in contours)
- {
- if (contour.Length < 100)
- {
- foreach (OpenCvSharp.Point point in contour)
- {
- erzhi.Set<byte>(point.Y, point.X, 255);
- }
- pointss.Add(contour);
- }
- }
- Cv2.FillPoly(erzhi, pointss, new Scalar(255));
- // 二次轮廓
- Cv2.FindContours(erzhi, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
- // 计算所有轮廓质点
- List<Point2d> massPoints = new List<Point2d>();
- foreach (OpenCvSharp.Point[] contour in contours)
- {
- OpenCvSharp.Moments moments = new OpenCvSharp.Moments(contour, false);
- massPoints.Add(new Point2d(moments.M10 / moments.M00, moments.M01 / moments.M00));
- }
- Mat labelMat = new Mat();
- Mat stats = new Mat();
- Mat centroids = new Mat();
- // 连通域数量
- int nccomps = Cv2.ConnectedComponentsWithStats(erzhi, labelMat, stats, centroids, PixelConnectivity.Connectivity8);
- //Cv2.ImWrite("erzhi2.tif", labelMat);
- //Cv2.ImWrite("erzhi3.tif", stats);
- //Cv2.ImWrite("erzhi4.tif", centroids);
- // 连通域质点
- Dictionary<int, Point2d> keyValues = new Dictionary<int, Point2d>();
- massLabelPoints.Clear();
- foreach (var item in massPoints)
- {
- if (double.IsNaN(item.Y) || double.IsNaN(item.X))
- {
- continue;
- }
- int label = labelMat.At<int>((int)item.Y, (int)item.X);
- if (0 <= label && label <= nccomps)
- {
- keyValues[label] = item;
- }
- }
- // 矩形边线上的连通域
- ArrayList nccompSelect = new ArrayList();
- foreach (var pointF in pointFs)
- {
- int label = labelMat.At<int>((int)pointF.Y, (int)pointF.X);
- if (!nccompSelect.Contains(label) && keyValues.ContainsKey(label) && keyValues[label] != null)
- {
- nccompSelect.Add(label);
- //if (keyValues.ContainsKey(label) && keyValues[label] != null)
- massLabelPoints.Add(keyValues[label]);
- }
- }
- // 矩形内的连通域
- int within = 0;
- ArrayList inccompSelect = new ArrayList();
- // 圆形
- if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
- {
- foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
- {
- foreach (var keyValue in keyValues)
- {
- //求点到圆心的距离
- double c = BasicCalculationHelper.GetDistance(new PointF((float)keyValue.Value.X, (float)keyValue.Value.Y), new PointF(rectangleF.X + rectangleF.Width / 2, rectangleF.Y + rectangleF.Height / 2), 10);
- if (!nccompSelect.Contains(keyValue.Key) && c < this.lineDiameter / 2)
- {
- if (!inccompSelect.Contains(keyValue.Key))
- {
- within++;
- inccompSelect.Add(keyValue.Key);
- if (keyValue.Value != null)
- massLabelPoints.Add(keyValue.Value);
- }
- }
- }
- }
- }
- }
- // 矩形
- if (grainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
- {
- foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
- {
- if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
- {
- foreach (var keyValue in keyValues)
- {
- if (!nccompSelect.Contains(keyValue.Key) && keyValue.Value.X > rectangleF.X && keyValue.Value.X < rectangleF.Right
- && keyValue.Value.Y > rectangleF.Y && keyValue.Value.Y < rectangleF.Bottom)
- {
- if (!inccompSelect.Contains(keyValue.Key))
- {
- within++;
- inccompSelect.Add(keyValue.Key);
- if (keyValue.Value != null)
- massLabelPoints.Add(keyValue.Value);
- }
- }
- }
- }
- }
- }
- Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC4);
- //Mat temp = new Mat(erzhi.Size(), MatType.CV_8UC1);
- Random rd = new Random();
- List<Vec4b> colors = new List<Vec4b>(nccomps);
- colors.Add(new Vec4b(0, 0, 0, 0));
- for (int i = 1; i < nccomps; i++)
- {
- //colors.Add(new Vec3b(255, 255, 255));
- colors.Add(new Vec4b(((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), ((byte)(rd.Next() % 256)), 255));
- }
- for (int y = 0; y < temp.Rows; y++)
- {
- for (int x = 0; x < temp.Cols; x++)
- {
- int label = labelMat.At<int>(y, x);
- if (nccompSelect.Contains(label))
- temp.Set<Vec4b>(y, x, colors[label]);
- if (inccompSelect.Contains(label))
- temp.Set<Vec4b>(y, x, colors[label]);
- //temp.Set<Vec4b>(y, x, new Vec4b(127, 127, 127, 127));
- ////if (0 <= label && label <= nccomps)
- ////{
- //// temp.Set<Vec3b>(y, x, colors[label]);
- ////}
- }
- }
- foreach (var item in massPoints)
- {
- if (double.IsNaN(item.Y) || double.IsNaN(item.X))
- {
- continue;
- }
- temp.Set<Vec4b>((int)item.Y, (int)item.X, new Vec4b(0, 0, 255, 255));
- }
- //Cv2.ImWrite("erzhi5.tif", temp);
- ////Cv2.ImShow("temp", temp);
- this.documentWorkspace.PhaseModels[2].mat = temp;
- this.documentWorkspace.Refresh();
- return within + (double)nccompSelect.Count / 2;
- }
- /// <summary>
- /// 使用圆心及半径得到圆的轮廓
- /// </summary>
- /// <param name="center">圆心</param>
- /// <param name="radius">半径</param>
- /// <returns></returns>
- public OpenCvSharp.Point[] roundOutline(Point center, int radius)
- {
- Mat mat = new Mat((int)(radius * 2.1), (int)(radius * 2.1), MatType.CV_8UC1, new Scalar(0, 0, 0));
- OpenCvSharp.Point point = new OpenCvSharp.Point(mat.Cols / 2, mat.Rows / 2);
- Cv2.Circle(mat, point, radius, new Scalar(255, 255, 255), -1);
- OpenCvSharp.Point[][] contours;
- HierarchyIndex[] hierarchy;
- Cv2.FindContours(mat, out contours, out hierarchy, RetrievalModes.CComp, ContourApproximationModes.ApproxNone);
- OpenCvSharp.Point[] roundOutline = contours[0];
- for (int i = 0; i < roundOutline.Length; i++)
- {
- roundOutline[i].X = roundOutline[i].X - point.X + center.X;
- roundOutline[i].Y = roundOutline[i].Y - point.Y + center.Y;
- }
- return roundOutline;
- }
- }
- }
|