NO IMAGE

Mat Basic Processing2

Merge Example Code: // // simple composition: Merge example // // 2×2 matrix Mat m1 = new Mat (2, 2, CvType.CV_64FC1); m1.put (0, 0, 1.0, 2.0, 3.0, 4.0); Mat m2 = new Mat (2, 2, CvType.CV_64FC1); m2.put (0, 0, 1.1, 2.1, 3.1, 4.1); Mat m3 = new Mat (2, 2, CvType.CV_64FC1); m3.put (0, 0, 1.2, 2.2, 3.2, 4.2); List<Mat> mv = new List<Mat>(); mv.Add (m1); mv.Add (m2); mv.Add (m3); // merge Mat m_merged = new Mat(); Core.merge (mv, m_merged); // dump Debug.Log (“”m_merged=”” + m_merged.dump()); Execution Result: m_merged=[1, 1.1, 1.2, 2, 2.1, 2.2; 3, 3.1, 3.2, 4, 4.1, 4.2] MixChannels Example Code: // // complex composition: mixChannels example // // 2×2 matrix Mat m1 = new Mat (2, 2, CvType.CV_64FC1); m1.put (0, 0, 1.0, 2.0, 3.0, 4.0); Mat m2 = new Mat (2, 2, CvType.CV_64FC1); m2.put (0, 0, 1.1, 2.1, 3.1, 4.1); Mat m3 = new Mat (2, 2, CvType.CV_64FC1); m3.put (0, 0, 1.2, 2.2, 3.2, 4.2); List<Mat> mv = new List<Mat>(); mv.Add (m1); mv.Add (m2); mv.Add (m3); // mat for output must be allocated. Mat m_mixed1 = new Mat(2, 2, CvType.CV_64FC2); Mat m_mixed2 = new Mat(2, 2, CvType.CV_64FC2); MatOfInt fromTo = new MatOfInt (0,0, 1,1, 1,3, 2,2); List<Mat> mixv = new List<Mat> (); mixv.Add (m_mixed1); mixv.Add (m_mixed2); // mix Core.mixChannels (mv, mixv, fromTo); // dump Debug.Log (“”m_mixed1=”” + m_mixed1.dump()); […]

NO IMAGE

Mat Basic Processing1

Initialization Example Code: // // initialization example // // 3×3 matrix (set array value) Mat mat1 = new Mat (3, 3, CvType.CV_64FC1); mat1.put (0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); Debug.Log (“”mat1=”” + mat1.dump()); // 2×2 rotation matrix double angle = 30, a = Math.Cos(angle*Math.PI/180), b = Math.Sin(angle*Math.PI/180); Mat mat2 = new Mat (2, 2, CvType.CV_64FC1); mat2.put (0, 0, a, -b, b, a); Debug.Log (“”mat2=”” + mat2.dump()); // 5×5 all 1’s matrix Mat mat3 = Mat.ones(5, 5, CvType.CV_64FC1); Debug.Log (“”mat3=”” + mat3.dump()); // 5×5 all zero’s matrix Mat mat4 = Mat.zeros(5, 5, CvType.CV_64FC1); Debug.Log (“”mat4=”” + mat4.dump()); // 5×5 identity matrix Mat mat5 = Mat.eye(5, 5, CvType.CV_64FC1); Debug.Log (“”mat5=”” + mat5.dump()); // 3×3 initialize with a constant Mat mat6 = new Mat (3, 3, CvType.CV_64FC1, new Scalar(5)); Debug.Log (“”mat6=”” + mat6.dump()); // 3×2 initialize with a uniform distribution random number Mat mat7 = new Mat (3, 2, CvType.CV_8UC1); Core.randu (mat7, 0, 256); Debug.Log (“”mat7=”” + mat7.dump()); // 3×2 initialize with a normal distribution random number Mat mat8 = new Mat (3, 2, CvType.CV_8UC1); Core.randn (mat8, 128, 10); Debug.Log (“”mat8=”” + mat8.dump()); Execution Result: mat1=[1, 2, 3; 4, 5, 6; 7, 8, 9] mat2=[0.8660254037844387, -0.4999999999999999; 0.4999999999999999, 0.8660254037844387] mat3=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; […]

Way to translation of Mat class operators defined in C++

This is a list of implemented matrix operations that can be combined in arbitrary complex expressions (here A, B stand for matrices ( Mat ), s for a scalar ( Scalar ), alpha for a real-valued scalar ( double )):   c++ OpenCVForUnity(C#) Addition, subtraction, negation: A+B, A-B, A+s, A-s, s+A, s-A, -A A + B M1 + M2 Core.add (M1, M2, M_dst) A – B M1 – M2 Core.subtract (M1, M2, M_dst) A + s M1 + s Core.add (M1, s, M_dst) A – s M1 – s Core.subtract (M1, s, M_dst) -A -M1 Core.multiply (M1, Scalar.all (-1), M_dst) Scaling: A*alpha A/alpha A * α M1 * 3 Core.multiply (M1, Scalar.all (3), M_dst) A / α M1 / 3 Core.divide (M1, Scalar.all (3), M_dst) Per-element multiplication and division: A.mul(B), A/B, alpha/A A.mul(B) M1.mul(M2) M1.mul (M2) A / B M1 / M2 Core.divide (M1, M2, M_dst) α / A 3 / M1 Core.divide (new Mat (M1.size (), M1.type (), Scalar.all (3)), M1, M_dst) Matrix multiplication: A*B A * B M1 * M2 Core.gemm (M1, M2, 1, new Mat (), 0, M_dst) Comparison: A cmpop B, A cmpop alpha, alpha cmpop A, where cmpop is one of :  >, >=, ==, !=, <=, <. The result of comparison is an 8-bit single channel mask whose elements are set to 255 (if the particular element or pair of elements satisfy […]