예제 #1
0
        FrameData processFrames(ImageFrame imageFrame, ImageFrame prevImageFrame, ImageSetting imageSetting)
        {
            int blockChange = 0;

            FrameData frameData = new FrameData();
            List<bool> rowChangeBits = new List<bool>();
                List<bool> columnChangeBits = new List<bool>();

            for(int i =0;i<imageSetting.Height/imageSetting.BlockSize;i++)
            {
                bool rowChange = false;
                List<bool> columnChange = new List<bool>();

                int rowFirstBlock = imageSetting.Height/imageSetting.BlockSize*i;

                for (int j = 0; j < imageSetting.Width / imageSetting.BlockSize; j++)
                {
                    bool changeBlock = false;
                    int position = rowFirstBlock + j;

                    if (!imageFrame.RPixels.ElementAt(position).Equals(prevImageFrame.RPixels.ElementAt(position)))
                        changeBlock = true;

                    if (!imageFrame.GPixels.ElementAt(position).Equals(prevImageFrame.GPixels.ElementAt(position)))
                        changeBlock = true;

                    if (!imageFrame.BPixels.ElementAt(position).Equals(prevImageFrame.BPixels.ElementAt(position)))
                        changeBlock = true;
                    if (changeBlock)
                    {
                        blockChange++;
                        rowChange = true;
                        columnChange.Add(true);

                        frameData.RPixels.Add(imageFrame.RPixels.ElementAt(position));
                        frameData.GPixels.Add(imageFrame.GPixels.ElementAt(position));
                        frameData.BPixels.Add(imageFrame.BPixels.ElementAt(position));

                    }
                    else
                    {
                        columnChange.Add(false);
                    }

                }
                if (rowChange)
                {
                    rowChangeBits.Add(true);
                    columnChangeBits.AddRange(columnChange);
                }
                else
                {
                    rowChangeBits.Add(false);
                }

            }
            frameData.rowChangeBits = new BitArray(rowChangeBits.ToArray());
            frameData.columnChangeBits = new BitArray(columnChangeBits.ToArray());
            //MessageBox.Show("int processImageLLLLLLLLLLLLLLLLLLLlll" + "frame Data : rowchange" + frameData.rowChangeBits.Length + "frame Data : colchange" + frameData.columnChangeBits.Length +
            //       "frame Data : RP" + frameData.RPixels.Count + "frame Data : GP" + frameData.GPixels.Count +
            //           "frame Data :BP" + frameData.BPixels.Count);

            return frameData;
        }
예제 #2
0
        Image reProcessFrame(Image prevImage, FrameData frameData, ImageSetting imageSetting)
        {
            Image image;
                Bitmap bitmap = new Bitmap(imageSetting.Width, imageSetting.Height);
                Bitmap prevBitmap = new Bitmap(prevImage);
                bitmap = prevBitmap;
                int RPixel;
                int GPixel;
                int BPixel;

                int columnChangeNum = 0;

                int row = -1;

                int changedBlockNum = 0;

                bool rowChanges = false;
                bool blockChange = false;

                int i=0;
                int j=0;
                try
                {

                for (   i = 0; i < imageSetting.Height; i += imageSetting.BlockSize)
                {
                    if (frameData.rowChangeBits[i/imageSetting.BlockSize])
                    {
                        rowChanges = true;
                        row++;
                    }
                    else
                        continue;

                    for (  j = 0; j < imageSetting.Width; j += imageSetting.BlockSize)
                    {

                        columnChangeNum = row * imageSetting.Width / imageSetting.BlockSize + j/imageSetting.BlockSize;
                        blockChange = frameData.columnChangeBits[columnChangeNum];
                        if (!blockChange)
                            continue;
                        else
                        {

                            RPixel = frameData.RPixels[changedBlockNum];
                            GPixel = frameData.GPixels[changedBlockNum];
                            BPixel = frameData.BPixels[changedBlockNum]; ;

                            changedBlockNum++;

                            for (int k = i; k < imageSetting.BlockSize; k++)
                                for (int l = j; l < imageSetting.BlockSize; l++)
                                {

                                    Color newcol = Color.FromArgb(RPixel, GPixel, BPixel);
                                    bitmap.SetPixel(k, l, newcol);

                                }
                        }

                    }

                }

                image = (Image)bitmap;

                return image;

            }
            catch (Exception ex)
            {
                MessageBox.Show("repocess frameLLLLLLLLLLLLLLLLLLLlll" + " frame Data : rowchange"+frameData.rowChangeBits.Length+ " frame Data : colchange"+frameData.columnChangeBits.Length+
                    "frame Data : RP"+frameData.RPixels.Count+ " frame Data : GP"+frameData.GPixels.Count+" rowchange "+rowChanges
                    +" i "+i+" j "+j+
                    " frame Data :BP"+frameData.BPixels.Count+" blcok change "+blockChange+" changedBlockNum"+changedBlockNum

               +"change col "+columnChangeNum+"ex "+ex.ToString());
            }
            return null;
        }
예제 #3
0
        ImageFrame extractPixels(Bitmap source, ImageSetting imageSetting)
        {
            ImageFrame imageFrame = new ImageFrame();
            int width = imageSetting.Width;
            int height = imageSetting.Height;
            //MessageBox.Show("I lll" + image.Height+ width+ height);
               // Bitmap source = null;//= new Bitmap(width, height, PixelFormat.Format24bppRgb);

             int RPixel;
            int GPixel;
            int BPixel;

            for(int i =0; i<imageSetting.Width; i+=imageSetting.BlockSize)

                for (int j = 0; j < imageSetting.Height; j += imageSetting.BlockSize)
                {
                    RPixel = 0;
                    GPixel = 0;
                    BPixel = 0;
                    for (int k = i; k < imageSetting.BlockSize; k++)
                        for (int l = j; l < imageSetting.BlockSize; l++)
                        {
                            RPixel += source.GetPixel(k, l).R;
                            GPixel += source.GetPixel(k, l).G;
                            BPixel += source.GetPixel(k, l).B;
                        }
                    RPixel /= imageSetting.BlockSize;
                    GPixel /= imageSetting.BlockSize;
                    BPixel /= imageSetting.BlockSize;

                    imageFrame.RPixels.Add(toByte(RPixel));
                    imageFrame.GPixels.Add(toByte(GPixel));
                    imageFrame.BPixels.Add(toByte(BPixel));

                }
            return imageFrame;
        }
예제 #4
0
        private void captureImage(Object obj)
        {
            int ticks = 0;
            int time = 0;

            int FrameNumber;
            int currentFrame;
            char state = 'd';
            Boolean capture = false;
            Boolean send = false;
            int synch = 0;
            Image imagCapture;
            ImageFrame imageFrame = new ImageFrame();
            ImageSetting imageSett = new ImageSetting();
            Bitmap bitmap;
            try
            {

                while (true)

                {
                    //Console.WriteLine("Hello capturing");
                    lock (this)
                    {
                        FrameNumber = FRAMENUMBER;
                        currentFrame = currentFrameNumber;
                        capture = onCapture;
                        imageSett = imageSetting;
                    }
                    ticks = Environment.TickCount;

                    //Thread.Sleep(1000);
                    while (capture)
                    {
                        if(send == false)
                        lock(this)
                        {
                        send = onSending;
                        }
                        try
                        {
                          //  Bitmap bitmap;
                            lock (this)
                            {

                                imagCapture = pictureBox1.Image;
                            //    bitmap = new Bitmap(pictureBox1.Image);

                            }
                            if (imagCapture == null)
                            {
                      //          MessageBox.Show("imagCapture is null");
                                continue;
                            }
                             lock(this)
                            {
                                currentFrame = currentFrameNumber;
                                states[currentFrame] = 'p';
                            }

                            int width = imageSett.Width;
                            int height = imageSett.Height;

                            try
                            {

                                bitmap = new Bitmap(imagCapture, width, height);
                                imageFrame = extractPixels(bitmap, imageSett);

                            }
                            catch (Exception ex)
                            {
                                //MessageBox.Show("Error in bitmap" + ex.ToString());
                                continue;
                            }

                            lock (this)
                            {
                                images[currentFrame] = imagCapture;
                                imageFrames[currentFrame] = imageFrame;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error in capturing...thread"+ex.ToString());

                        }

                        //Increment the current frame of program
                        lock (this)
                        {
                                currentFrameNumber = (currentFrameNumber + 1) % FrameNumber;

                        }
                        time = 1000 / FrameNumber - (Environment.TickCount - ticks);   // k ho yo..............

                        if (time > 0)
                        {
                            Thread.Sleep(time);
                            //Console.WriteLine("Thread Sleep");
                        }
                        //else
                        //    Console.WriteLine("no sleeping..." + (-time).ToString());
                        ticks = Environment.TickCount;
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in capture Image!"+ex.ToString());
              }
        }
예제 #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            //bool[] data = new bool[9];
            //data[0] = true;
            //data[1] = true;
            //data[2] = false;
            //data[3] = true;
            //data[4] = true;
            //data[5] = false;
            //data[6] = false;
            //data[7] = true;
            //data[8] = true;

            //FrameData frm = new FrameData();
            //BitArray btarray = new BitArray(data);

            //for (int i = 0; i < btarray.Length; i++)
            //{
            //    Console.WriteLine(btarray[i]);
            //}
            //Console.WriteLine("fsdfs");
            //byte[] databyte = frm.ToByteArray(btarray);

            //BitArray bt = new BitArray(databyte);
            //for (int i = 0; i < bt.Length; i++)
            //{
            //    Console.WriteLine(bt[i]);
            //}

            ImageSetting imgSetting = new ImageSetting(320, 240, 8, 8);
            byte[] imgByte = imgSetting.toByte();
            ImageSetting imgSetting1 = new ImageSetting(imgByte);
            Console.WriteLine("Height : " + imgSetting1.Height + "\nWidth : " + imgSetting1.Width + "\nblock : " + imgSetting1.BlockSize + "\nColorBIts : " + imgSetting1.ColorBits);

            int rowDataNo = imgSetting.Height / imgSetting.BlockSize;
            Console.WriteLine("Row No :" + rowDataNo);

            bool[] rowChangeBits = new bool[rowDataNo];

            for (int i = 0; i < rowDataNo; i++)
            {
                rowChangeBits[i] = true;
            }

            int colNo = imgSetting.Width / imgSetting.BlockSize;
            bool[] colChangeBits = new bool[colNo * rowDataNo];
            int count = 0;
            Console.WriteLine("total column change bits no : " + rowDataNo * colNo);
            for (int j = 0; j < rowDataNo; j++)
            {
                for (int k = 0; k < colNo; k++)
                {
                    colChangeBits[count] = true;
                    count++;
                }
            }

            int totalchange = rowDataNo * colNo;
            List<byte> RPixel = new List<byte>();
            List<byte> GPixel = new List<byte>();
            List<byte> BPixel = new List<byte>();
            char R = 'R';
            char G = 'G';
            char B = 'B';
            for (int i = 0; i < totalchange; i++)
            {
                RPixel.Add((byte)R);
                GPixel.Add((byte)G);
                BPixel.Add((byte)B);
            }

            FrameData frmData = new FrameData(rowChangeBits, colChangeBits, RPixel, GPixel, BPixel);

            byte[] frmByte = frmData.toBytes();

            FrameData frmData1 = new FrameData(frmByte, imgSetting);
            int c = 0;
            Console.WriteLine("Row Change Bits : " + rowChangeBits.Length + "------" + frmData1.rowChangeBits.Length);
            for (int i = 0; i < rowDataNo; i++)
            {
                Console.WriteLine(i + "-" + frmData1.rowChangeBits[i]);
                if (frmData1.rowChangeBits[i])
                    c++;
            }

            count = 0;
            Console.WriteLine("Column Change Bits : " + colChangeBits.Length + "----" + frmData1.columnChangeBits.Length + "true data : " + c);
            for (int i = 0; i < c; i++)
            {
                for (int j = 0; j < colNo; j++)
                {
                    Console.WriteLine(frmData1.columnChangeBits[count]);
                    count++;
                }
            }

            for (int i = 0; i < colNo * c; i++)
            {
                Console.WriteLine((char)frmData1.RPixels[i]);
                Console.WriteLine((char)frmData1.GPixels[i]);
                Console.WriteLine((char)frmData1.BPixels[i]);

            }
            Console.WriteLine("No of R = " + colNo * c);
        }
예제 #6
0
        public FrameData(byte[] frameData, ImageSetting imgSetting)
        {
            //MessageBox.Show("in cons iamgesett" + imgSetting.Height + imgSetting.Width + imgSetting.BlockSize + imgSetting.ColorBits);

            RPixels = new List<byte>();
            GPixels = new List<byte>();
            BPixels = new List<byte>();
            int rowLen = imgSetting.Height / imgSetting.BlockSize;
            int rowBytelen = rowLen/8;
            if(rowLen%8!=0)
                rowBytelen++;
            int pos = 0;
            List<byte> rowData = new List<byte>();
            for (int i = 0; i < rowBytelen; i++)
            {
                rowData.Add(frameData[i]);
                pos++;
            }
            BitArray rowBits = new BitArray(rowData.ToArray());
            rowChangeBits = new BitArray(rowLen);
            int columnChange = 0;

            for (int i = 0; i < rowLen; i++)
            {

                rowChangeBits[i] = rowBits[i];
                if (rowBits[i])
                    columnChange++;

            }

            //MessageBox.Show("frombyte...rowLen " + rowLen+"columnChagen"+columnChange);
            int colNo = imgSetting.Width / imgSetting.BlockSize;
            int columnByteLen = columnChange*colNo / 8;
            if (columnChange*colNo % 8 != 0)
                columnByteLen++;
            List<byte> columnData = new List<byte>();
            for (int j = 0; j < columnByteLen; j++)
            {
                columnData.Add(frameData[pos]);
                pos++;
            }
            int frameDataLen = frameData.Length;

            int colorSize = (frameDataLen - pos)/3;

            if ((frameDataLen - pos) % 3 != 0)
                Console.WriteLine("not divisible bye 3" + (frameDataLen - pos) % 3);

            BitArray columnBits= new BitArray(columnData.ToArray());
            columnChangeBits = new BitArray(columnChange*colNo);
            for (int i = 0; i < (columnChange*colNo); i++)
            {
                columnChangeBits[i] = columnBits[i];
            }
               //     MessageBox.Show("frombyte...columnChageBits " + columnChange + "X" + colNo + "frameDataLength: " + frameDataLen + " pos " + pos + "colorSize " +
               // colorSize);

            for (int i = 0; i < colorSize; i++)
            {
                RPixels.Add(frameData[pos]);
                pos++;
            }
            for (int i = 0; i < colorSize; i++)
            {
                GPixels.Add(frameData[pos]);
                pos++;
            }
            for (int i = 0; i < colorSize; i++)
            {
                BPixels.Add(frameData[pos]);
                pos++;
            }
        }
예제 #7
0
        private void ServerFrm_Load(object sender, EventArgs e)
        {
            webcam = new WebCam();
            webcam.initializeWebCam(ref pictureBox1);
            localMachineInfo();
            txtPortNo.Text = portNo.ToString();
            txtHostname.Text = hostname;
            txtHostIP.Text = hostIp;
            sendBtn.Enabled = false;
            stopServerBtn.Enabled = false;
            onCapture = false;
            onSending = false;
            images = new Image[FRAMENUMBER];
            states = new char[FRAMENUMBER];
            imageSetting = new ImageSetting();
            imageFrames = new ImageFrame[FRAMENUMBER];
            framesData = new FrameData[FRAMENUMBER];

            resHeight = 640;
            resWidth = 720;

            currentFrameNumber = 0;
            callBackCapture = new WaitCallback(captureImage);
            callBackProcess = new WaitCallback(processImage);
            callBackSend = new WaitCallback(sendImage);
        }