//必做任务 输入图像选择 private void button_inputImg_Click(object sender, EventArgs e) { openFileDialog_inputImg.Filter = "图片文件(*.jpg,*.bmp,*.png)|*.jpg;*.bmp;*.png"; if (openFileDialog_inputImg.ShowDialog() == DialogResult.OK) { string img_path = openFileDialog_inputImg.FileName; //图片路径 //Mat img = CvInvoke.Imread(img_path); Bitmap bm_source = show_img(img_path, pictureBox_inputImg); distort_class = new Pic_distort(); distort_class.setInputImg(bm_source); } }
//切除黑边 public void BlackCut_tran(string interp_method = "最近邻") { blackCut_distort = new Pic_distort(); blackCut_distort.inputImg = new myMat(); blackCut_distort.inputImg.getData_Mat(sourceFace_distort.resultImg); blackCut_distort.resultImg = new myMat(); blackCut_distort.resultImg.init_bytes(blackCut_distort.inputImg.height, blackCut_distort.inputImg.width); /*Bitmap bm = blackCut_distort.inputImg.img2Bitmap(); * Image<Bgr, byte> draw_img = new Image<Bgr, byte>(bm); * draw_img.Draw(new Cross2DF(new PointF((int)leftUp_point.j, (int)leftUp_point.i), 10, 10), new Bgr(0, 0, 255), 2); * draw_img.Draw(new Cross2DF(new PointF((int)leftDown_point.j, (int)leftDown_point.i), 10, 10), new Bgr(0, 0, 255), 2); * * CvInvoke.Imshow("a", draw_img); * CvInvoke.WaitKey();*/ double turn_angle = System.Math.Atan2((leftDown_point.j - leftUp_point.j), (leftDown_point.i - leftUp_point.i)); double height_scale = myMat.myCoor.getDis(leftUp_point, leftDown_point) / blackCut_distort.resultImg.height; for (int i = 0; i < blackCut_distort.inputImg.height; i++) { for (int j = 0; j < blackCut_distort.inputImg.width; j++) { if (i == blackCut_distort.inputImg.height - 3 && j == 0) { int a = 0; } myMat.myCoor sourceCoor = Turn_get_sourceCoor(i, j, turn_angle); sourceCoor.i *= height_scale; sourceCoor.j *= height_scale; sourceCoor.i += (int)leftUp_point.i; sourceCoor.j += (int)leftUp_point.j; Color c = blackCut_distort.interp(sourceCoor, interp_method); blackCut_distort.resultImg.set_rgb(c, new myMat.myCoor(i, j)); } } /*Bitmap bm2 = blackCut_distort.resultImg.img2Bitmap(); * Image<Bgr, byte> draw_img2 = new Image<Bgr, byte>(bm2); * * CvInvoke.Imshow("a", draw_img2); * CvInvoke.WaitKey();*/ int min_y, max_y, max_x, min_x; blackCut_getIJ(out min_y, out max_y, out min_x, out max_x); int new_height = max_x - min_x + 1; int new_width = max_y - min_y + 1; for (int i = 0; i < new_height; i++) { for (int j = 0; j < new_width; j++) { int i_cut = min_x + i; int j_cut = min_y + j; Color source_color = blackCut_distort.resultImg.getRGB(new myMat.myCoor(i_cut, j_cut)); blackCut_distort.resultImg.set_rgb(source_color, new myMat.myCoor(i, j)); } } blackCut_distort.resultImg.height = new_height; blackCut_distort.resultImg.width = new_width; }
public double[,] W; //坐标变换所用参数 //保存原图像 public void set_source_img(Bitmap bm) { sourceFace_distort = new Pic_distort(); sourceFace_distort.setInputImg(bm); }