static Mat getTransformedImg(GMatrix m, Mat mat) { return(netCvLib.calib3d.Calib.TransformImg(m.To2DArray(), mat)); //var size = mat.Size; //Mat tm = new Mat(); //Matrix<double> tranMat = new Matrix<double>(m.To2DArray()); //CvInvoke.WarpPerspective(mat, tm, tranMat, size); //return tm; }
public Bitmap TransformBmp(Bitmap bmp, GMatrix ma) { Bitmap outBmp = new Bitmap(bmp); using (var g = Graphics.FromImage(outBmp)) { g.Clear(System.Drawing.Color.White); } //for (int y = 0; y < bmp.Height; y++) //{ // for (int x = 0; x < bmp.Width; x++) // { // var pix = bmp.GetPixel(x, y); // var res = m.dot(new GMatrix(new double[] { x, y, 1 }, 3, 1)); // var zt = res.storage[2][0]; // var xt = res.storage[0][0] / zt; // var yt = res.storage[1][0] / zt; // if (xt > 0 && yt > 0) // { // if (xt < bmp.Width && yt < bmp.Height) // { // outBmp.SetPixel((int)xt, (int)yt, pix); // } // } // } //} var mi = GMatrix.Inverse3x3(ma); for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { var res = mi.dot(new GMatrix(new double[] { x, y, 1 }, 3, 1)); var zt = res.storage[2][0]; var xt = (int)(res.storage[0][0] / zt); var yt = (int)(res.storage[1][0] / zt); if (xt > 0 && yt > 0 && xt < bmp.Width && yt < bmp.Height) { var pix = bmp.GetPixel(xt, yt); outBmp.SetPixel(x, y, pix); } } } return(outBmp); }
private LineSlop GetEpLineABC(PointFloat pts, PointSide side, GMatrix f) { if (side == PointSide.Right) { f = f.tranpose(); } var gm = f.dot(new GMatrix(new double[3, 1] { { pts.X }, { pts.Y }, { 1 } })); var ms = gm.storage; var a = ms[0][0]; var b = ms[1][0]; var c = ms[2][0]; return(new LineSlop(a, b, c)); }
public void DrawMatrix(Texture p_texture, BlendMode p_srcBlendMode, BlendMode p_dstBlendMode, GMatrix p_matrix, float p_red, float p_green, float p_blue, float p_alpha, float p_u, float p_v, float p_uScale, float p_vScale, float p_textureWidth, float p_textureHeight, float p_texturePivotX, float p_texturePivotY, IGNativeUnityFilter p_filter) { if (!Object.ReferenceEquals(_lastTexture, p_texture) || p_srcBlendMode != _lastSrcBlendMode || p_dstBlendMode != _lastDstBlendMode || _renderType != 1 || _lastFilter != p_filter) { if (_lastTexture) { FlushRenderer(); } Mesh mesh = _meshes[_currentBatchIndex]; Material material = (p_filter == null) ? _defaultMaterial : p_filter.getMaterial(); _lastFilter = p_filter; if (_lastFilter != null) { _lastFilter.bind(); } material.mainTexture = p_texture; _lastTexture = p_texture; material.SetInt("BlendSrcMode", (int)p_srcBlendMode); material.SetInt("BlendDstMode", (int)p_dstBlendMode); _lastSrcBlendMode = p_srcBlendMode; _lastDstBlendMode = p_dstBlendMode; _renderType = 1; } float tx; float ty; int vertexIndex = _quadIndex * 4; tx = -p_textureWidth / 2 - p_texturePivotX; ty = -p_textureHeight / 2 - p_texturePivotY; _vertices[vertexIndex].x = (float)(p_matrix.a * tx + p_matrix.c * ty + p_matrix.tx); _vertices[vertexIndex].y = (float)(p_matrix.b * tx + p_matrix.d * ty + p_matrix.ty); _uvs[vertexIndex].x = p_u; _uvs[vertexIndex].y = 1 - p_v; _colors[vertexIndex].r = p_red; _colors[vertexIndex].g = p_green; _colors[vertexIndex].b = p_blue; _colors[vertexIndex].a = p_alpha; tx = -p_textureWidth / 2 - p_texturePivotX; ty = p_textureHeight / 2 - p_texturePivotY; vertexIndex++; _vertices[vertexIndex].x = (float)(p_matrix.a * tx + p_matrix.c * ty + p_matrix.tx); _vertices[vertexIndex].y = (float)(p_matrix.b * tx + p_matrix.d * ty + p_matrix.ty); _uvs[vertexIndex].x = p_u; _uvs[vertexIndex].y = 1 - (p_v + p_vScale); _colors[vertexIndex].r = p_red; _colors[vertexIndex].g = p_green; _colors[vertexIndex].b = p_blue; _colors[vertexIndex].a = p_alpha; tx = p_textureWidth / 2 - p_texturePivotX; ty = p_textureHeight / 2 - p_texturePivotY; vertexIndex++; _vertices[vertexIndex].x = (float)(p_matrix.a * tx + p_matrix.c * ty + p_matrix.tx); _vertices[vertexIndex].y = (float)(p_matrix.b * tx + p_matrix.d * ty + p_matrix.ty); _uvs[vertexIndex].x = p_u + p_uScale; _uvs[vertexIndex].y = 1 - (p_v + p_vScale); _colors[vertexIndex].r = p_red; _colors[vertexIndex].g = p_green; _colors[vertexIndex].b = p_blue; _colors[vertexIndex].a = p_alpha; tx = p_textureWidth / 2 - p_texturePivotX; ty = -p_textureHeight / 2 - p_texturePivotY; vertexIndex++; _vertices[vertexIndex].x = (float)(p_matrix.a * tx + p_matrix.c * ty + p_matrix.tx); _vertices[vertexIndex].y = (float)(p_matrix.b * tx + p_matrix.d * ty + p_matrix.ty); _uvs[vertexIndex].x = p_u + p_uScale; _uvs[vertexIndex].y = 1 - p_v; _colors[vertexIndex].r = p_red; _colors[vertexIndex].g = p_green; _colors[vertexIndex].b = p_blue; _colors[vertexIndex].a = p_alpha; _quadIndex++; if (_quadIndex >= _maxBatchSize) { FlushRenderer(); } }
static void Main(string[] args) { //TestData(); //return; double[] A = new double[] { 1, 1, 2, 3, 2, 1, 4, 2, 1, }; var jres = JacobSvd.JacobiSVD(new GMatrix(A, 3, 3)); GMatrix s = jres.getWMat(); //new GMatrix(new double[] { // jres.W[0], 0 ,0, // 0, jres.W[1], 0, // 0,0,jres.W[2] //}, 3, 3); //Console.WriteLine("U"); //Console.WriteLine(jres.U); //Console.WriteLine(jres.U.dot(jres.U.tranpose())); //Console.WriteLine("S"); //Console.WriteLine(s); //Console.WriteLine("V"); //Console.WriteLine(jres.Vt); //Console.WriteLine(jres.Vt.dot(jres.Vt.tranpose())); //Console.WriteLine(jres.U.dot(s).dot(jres.Vt)); //return; //var r = new GMatrix(new double[,] { { 1, 2 }, { 3, 4 } , { 1, 1 } }).cross(new GMatrix(new double[,] { { 1, 1 ,1}, { 3, 4 ,1} })); //Console.WriteLine(r); //new Calib().Calc(new PointF[] { // new Point(1,2), // new Point(3,4), // new Point(5,4), // new Point(6,4), // new Point(7,4), // new Point(8,4), // new Point(9,4), // new Point(10,4), // new Point(11,4), // new Point(12,4), // new Point(13,4), // new Point(14,4), //}, //new PointF[] { // new Point(1,2), // new Point(3,4), // new Point(3,4), // new Point(3,4), // new Point(3,4), // new Point(3,4), // new Point(3,4), // new Point(3,4), // new Point(3,4), // new Point(3,4), // new Point(3,4), // new Point(3,4), //} //); var lines = File.ReadAllLines(saveFileName_corners); var resa = stringToCorner(lines); for (int i = 0; i < 10; i++) { var res = Calib.CalcFundm(resa[0][i], resa[1][i]); Console.WriteLine(res); } Console.WriteLine(Calib.CalcFundm(resa[0].Take(10).SelectMany(x => x).ToArray(), resa[1].Take(10).SelectMany(x => x).ToArray())); Console.WriteLine("\nHomo\n"); for (int i = 0; i < 10; i++) { var res = Calib.EstimateHomography(resa[0][i]); Console.WriteLine(res); var res2 = Calib.EstimateHomography(resa[1][i]); Console.WriteLine(res2); Console.WriteLine("===================================="); } var intrinc1 = Calib.EstimateIntranics(resa[0]); Console.WriteLine("==================================== INCTRINS 1"); Console.WriteLine(intrinc1); var intrinc2 = Calib.EstimateIntranics(resa[1]); Console.WriteLine("==================================== INCTRINS 2"); Console.WriteLine(intrinc2); }
public MainWindow() { InitializeComponent(); var al = new List <PointFloat>(); var ar = new List <PointFloat>(); List <StereoPoints> allPts = new List <StereoPoints>(); PointFloat imgSize = null; foreach (var iii in images) { var left = CvInvoke.Imread($"{imageDir}\\Left_{iii}.jpg"); imgSize = new PointFloat(left.Width, left.Height); var right = CvInvoke.Imread($"{imageDir}\\Right_{iii}.jpg"); var corl = convertToPF(netCvLib.calib3d.Calib.findConers(left.ToImage <Gray, Byte>())); al.AddRange(corl); var corr = convertToPF(netCvLib.calib3d.Calib.findConers(right.ToImage <Gray, Byte>())); ar.AddRange(corr); allPts.Add(new StereoPoints { Left = corl, Right = corr }); File.WriteAllLines($"{imageDir}\\Left_{iii}.txt", cornerToString(corl)); File.WriteAllLines($"{imageDir}\\Right_{iii}.txt", cornerToString(corr)); var ff = com.veda.LinearAlg.Calib.CalcFundm((corl), (corr)); //Console.WriteLine(ff); } Console.WriteLine("F"); F = com.veda.LinearAlg.Calib.CalcFundm(al.ToArray(), ar.ToArray()); Console.WriteLine(F); calres = CalibRect.Rectify(allPts, imgSize); Console.WriteLine("Callres"); Console.WriteLine(calres.F); Console.WriteLine(calres.el.X.ToString("0.00") + " " + calres.el.Y.ToString("0.00")); Console.WriteLine(calres.LeftIntrinics); Console.WriteLine(calres.RightIntrinics); Console.WriteLine(calres.H1); Console.WriteLine(calres.H2); Console.WriteLine("E"); Console.WriteLine(calres.E); var rtl = calres.GetRT(calres.E); Console.WriteLine("RT from left"); Console.WriteLine(rtl.R); Console.WriteLine(rtl.T); who = 0; imgSelFunc(); for (int i = 0; i < cbs.Length; i++) { var cb = new CheckBox(); cb.Name = "chkEpl_" + i; cb.IsChecked = false; cb.Checked += Cb_Checked; cb.Unchecked += Cb_Checked; cbs[i] = cb; onChecks[i] = false; } foreach (var cb in cbs) { stkEpoles.Children.Add(cb); } }