コード例 #1
0
 //* CHECKBOX _ Negative *//
 private void checkBox_isNegative_CheckedChanged(object sender, EventArgs e)
 {
     Took3D.negativeImg(imgBox);
     imgBox.Copy(beforeErode);
     pictureBox.ImageIpl = imgBox;
 }
コード例 #2
0
        //* MODE : RING *//
        private IplImage mode_Ring(IplImage srcImg)
        {
            // 1. 링(고리) 생성
            IplImage temp = Properties.Resources.gr.ToIplImage();
            IplImage gr   = new IplImage(temp.Size, srcImg.Depth, srcImg.NChannels);

            temp.CvtColor(gr, ColorConversion.BgrToGray);
            temp.Dispose(); //해제


            // 2. 객체추출
            Took3D.checkSize(srcImg);
            int minX = Took3D.minX, minY = Took3D.minY;
            int maxX = Took3D.maxX - minX, maxY = Took3D.maxY - minY;

            srcImg.SetROI(new CvRect(minX, minY, maxX, maxY));
            IplImage src = new IplImage(maxX, maxY, srcImg.Depth, srcImg.NChannels);

            srcImg.Copy(src);


            // 3. 이미지 변환
            Took3D.negativeImg(src);


            // 4. 이미지 크기 조정
            IplImage gr_hole;

            int roi_X      = 37;
            int roi_Y      = 226;
            int roi_width  = 204;
            int roi_height = 175;

            //int X_wid = 240;
            //int Y_hei = 379;

            int setHeight = 0, setWidth = 0;

            if (src.Width > src.Height)
            {
                setWidth  = roi_width;
                setHeight = (roi_width * src.Height) / src.Width;

                if (setHeight > roi_height)
                {
                    setHeight = roi_height;
                    setWidth  = (roi_height * setWidth) / setHeight;
                }
                gr_hole = new IplImage(setWidth, setHeight, src.Depth, src.NChannels);
            }
            else if (src.Width < src.Height)
            {
                setHeight = roi_height;
                setWidth  = (roi_height * src.Width) / src.Height;

                if (setWidth > roi_width)
                {
                    setWidth  = roi_width;
                    setHeight = (roi_width * setHeight) / setWidth;
                }

                gr_hole = new IplImage(setWidth, setHeight, src.Depth, src.NChannels);
            }
            else
            {
                setHeight = roi_height;
                setWidth  = (roi_height * src.Width) / src.Height;
                gr_hole   = new IplImage(setWidth, setHeight, src.Depth, src.NChannels);
            }
            src.Resize(gr_hole, Interpolation.Cubic);


            //5. 위치 조정
            int mid_X = (roi_width / 2) - (gr_hole.Width / 2);

            gr.SetROI(roi_X + mid_X, roi_Y, gr_hole.Width, gr_hole.Height);


            //6. 합성
            gr_hole.Copy(gr);


            //7. 메모리 정리
            gr.ResetROI();
            srcImg.ResetROI();
            gr_hole.Dispose();
            src.Dispose();

            return(gr);
        }
コード例 #3
0
        //* MODE : STAMP *//
        private IplImage mode_Stamp(IplImage srcImg)
        {
            // 1. 객체추출
            Took3D.checkSize(srcImg);
            int minX = Took3D.minX, minY = Took3D.minY;
            int maxX = Took3D.maxX - minX, maxY = Took3D.maxY - minY;

            srcImg.SetROI(new CvRect(minX, minY, maxX + 1, maxY + 1));
            IplImage src = new IplImage(maxX + 1, maxY + 1, srcImg.Depth, srcImg.NChannels);

            srcImg.Copy(src);

            // 2. 도장이미지 생성
            IplImage stampImg = new IplImage(200, 200, src.Depth, src.NChannels);

            stampImg.Set(CvScalar.ScalarAll(255));

            // 3. 도장이미지 크기조정
            int roi_width  = 175;
            int roi_height = 175;

            IplImage gr_hole;
            int      setHeight = 0, setWidth = 0;

            if (src.Width > src.Height)
            {
                setWidth  = roi_width;
                setHeight = (roi_width * src.Height) / src.Width;

                if (setHeight > roi_height)
                {
                    setHeight = roi_height;
                    setWidth  = (roi_height * setWidth) / setHeight;
                }
                gr_hole = new IplImage(setWidth, setHeight, src.Depth, src.NChannels);
            }
            else if (src.Width < src.Height)
            {
                setHeight = roi_height;
                setWidth  = (roi_height * src.Width) / src.Height;

                if (setWidth > roi_width)
                {
                    setWidth  = roi_width;
                    setHeight = (roi_width * setHeight) / setWidth;
                }

                gr_hole = new IplImage(setWidth, setHeight, src.Depth, src.NChannels);
            }
            else
            {
                setHeight = roi_height;
                setWidth  = (roi_height * src.Width) / src.Height;
                gr_hole   = new IplImage(setWidth, setHeight, src.Depth, src.NChannels);
            }
            src.Resize(gr_hole, Interpolation.Cubic);

            // 4. 위치 조정
            int mid_X = (200 / 2) - (gr_hole.Width / 2);
            int mid_Y = (200 / 2) - (gr_hole.Height / 2);

            stampImg.SetROI(mid_X, mid_Y, gr_hole.Width, gr_hole.Height);

            // 5. 삽입
            gr_hole.Copy(stampImg);

            // 6. 메모리 정리
            srcImg.ResetROI();
            stampImg.ResetROI();
            gr_hole.Dispose();
            src.Dispose();

            return(stampImg);
        }
コード例 #4
0
        private IplImage Dot_Resize(IplImage srcImg)
        {
            // 1. 객체추출
            Took3D.checkSize(srcImg);
            int minX = Took3D.minX, minY = Took3D.minY;
            int maxX = Took3D.maxX - minX, maxY = Took3D.maxY - minY;

            srcImg.SetROI(new CvRect(minX, minY, maxX, maxY));
            IplImage src = new IplImage(maxX, maxY, srcImg.Depth, srcImg.NChannels);

            srcImg.Copy(src);

            // 2. 도트 밑판 생성
            IplImage dotBackImg = new IplImage(500, 500, src.Depth, src.NChannels);

            dotBackImg.Set(CvScalar.ScalarAll(255));

            // 3. 도트이미지 크기조정
            int roi_width  = 470;
            int roi_height = 470;

            IplImage temp;
            int      setHeight = 0, setWidth = 0;

            if (src.Width > src.Height)
            {
                setWidth  = roi_width;
                setHeight = (roi_width * src.Height) / src.Width;

                if (setHeight > roi_height)
                {
                    setHeight = roi_height;
                    setWidth  = (roi_height * setWidth) / setHeight;
                }
                temp = new IplImage(setWidth, setHeight, src.Depth, src.NChannels);
            }
            else if (src.Width < src.Height)
            {
                setHeight = roi_height;
                setWidth  = (roi_height * src.Width) / src.Height;

                if (setWidth > roi_width)
                {
                    setWidth  = roi_width;
                    setHeight = (roi_width * setHeight) / setWidth;
                }

                temp = new IplImage(setWidth, setHeight, src.Depth, src.NChannels);
            }
            else
            {
                setHeight = roi_height;
                setWidth  = (roi_height * src.Width) / src.Height;
                temp      = new IplImage(setWidth, setHeight, src.Depth, src.NChannels);
            }
            src.Resize(temp, Interpolation.Cubic);

            // 4. 위치 조정
            int mid_X = (500 / 2) - (temp.Width / 2);
            int mid_Y = (500 / 2) - (temp.Height / 2);

            dotBackImg.SetROI(mid_X, mid_Y, temp.Width, temp.Height);

            // 5. 삽입
            temp.Copy(dotBackImg);

            // 6. 메모리 정리
            srcImg.ResetROI();
            dotBackImg.ResetROI();
            temp.Dispose();
            src.Dispose();

            return(dotBackImg);
        }
コード例 #5
0
        //* BUTTON_CONVERT *//
        private void button_Convert_Click(object sender, EventArgs e)
        {
            IplImage tempImgBox;

            Took3D.SET_Z = Int32.Parse(textBox_SetZ.Text);
            if (isImgOpen == true)
            {
                switch (currentMode)
                {
                // <<DEFAULT>>
                case Mode.DEFAULT:
                    // 흰색 윤곽선 추가.
                    tempImgBox = new IplImage(imgBox.Width + 10, imgBox.Height + 10, BitDepth.U8, 1);
                    imgBox.CopyMakeBorder(tempImgBox, new CvPoint(5, 5), BorderType.Constant, CvScalar.ScalarAll(0xFF));

                    // 모델링
                    Took3D.START(tempImgBox);

                    if (radioButton_Polygon.Checked == true)
                    {
                        bool checkBottomMode = Took3D.bottomPolygon();
                        if (checkBottomMode == false)
                        {
                            radioButton_Background.Checked = true;
                        }

                        Took3D.binarySTL_Bottom();
                    }
                    else if (radioButton_Background.Checked == true)
                    {
                        Took3D.bottomBackground();
                        Took3D.binarySTL_BackBottom();
                    }
                    else
                    {
                        Took3D.binarySTL();
                    }
                    break;

                // <<STAMP>>
                case Mode.STAMP:
                    tempImgBox = mode_Stamp(imgBox);
                    Took3D.START(tempImgBox);
                    Took3D.stampModeling();
                    Took3D.binarySTL_BackBottom();

                    break;

                // <<DOT>>
                case Mode.DOT:
                    // 1. 크기조정
                    tempImgBox = Dot_Resize(imgBox);

                    // 2. 이미지 확대 ( 도트 원형 유지 )
                    IplImage dot_tmp = new IplImage(tempImgBox.Width * 10, tempImgBox.Height * 10, tempImgBox.Depth, tempImgBox.NChannels);
                    tempImgBox.Resize(dot_tmp, Interpolation.Cubic);
                    tempImgBox.Dispose();

                    // 3. 도트 이미지 생성
                    tempImgBox = mode_Dot(dot_tmp);
                    dot_tmp.Dispose();

                    // 4. 흰색윤곽추가
                    dot_tmp = new IplImage(tempImgBox.Width + 4, tempImgBox.Height + 4, tempImgBox.Depth, tempImgBox.NChannels);
                    tempImgBox.CopyMakeBorder(dot_tmp, new CvPoint(2, 2), BorderType.Constant, CvScalar.ScalarAll(0xFF));
                    tempImgBox = dot_tmp;

                    // 5. 이진화 시작
                    Took3D.START(tempImgBox);
                    Took3D.binarySTL();
                    break;


                // <<RING>>
                case Mode.RING:
                    tempImgBox = mode_Ring(imgBox);
                    Took3D.START(tempImgBox);
                    Took3D.binarySTL();
                    break;


                default:
                    break;
                }

                pictureBox.ImageIpl = Took3D.resultImage;

                //Console.WriteLine("minX : {0} minY : {1} maxX : {2} maxY : {3}", Took3D.minX, Took3D.minY, Took3D.maxX, Took3D.maxY);

                // 파일 저장 처리
                saveFileDialog1.Filter = "STL File(*.stl)|*.stl";
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    FileInfo file = new FileInfo(@"C:\TookTemp\output");
                    if (file.Exists)
                    {
                        File.Copy(@"C:\TookTemp\output", saveFileDialog1.FileName, true);
                        MessageBox.Show("완료");
                    }
                }
                //tempImgBox.Dispose();
            }
            else
            {
                MessageBox.Show("이미지를 선택해주세요!");
            }
        }