Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
GeneralRe: Property with "get" only, or a separate method? Pin
Matt U.18-Apr-14 8:16
Matt U.18-Apr-14 8:16 
GeneralRe: Property with "get" only, or a separate method? Pin
OriginalGriff18-Apr-14 8:32
mveOriginalGriff18-Apr-14 8:32 
AnswerRe: Property with "get" only, or a separate method? Pin
Ravi Bhavnani18-Apr-14 8:16
professionalRavi Bhavnani18-Apr-14 8:16 
GeneralRe: Property with "get" only, or a separate method? Pin
Matt U.18-Apr-14 8:19
Matt U.18-Apr-14 8:19 
GeneralRe: Property with "get" only, or a separate method? Pin
Ravi Bhavnani18-Apr-14 8:59
professionalRavi Bhavnani18-Apr-14 8:59 
Questionmarching cubes Pin
Member 1071125918-Apr-14 7:25
Member 1071125918-Apr-14 7:25 
AnswerRe: marching cubes Pin
OriginalGriff18-Apr-14 8:10
mveOriginalGriff18-Apr-14 8:10 
QuestionBackground Substraction and HOG Pin
Member 1042078418-Apr-14 5:42
Member 1042078418-Apr-14 5:42 
Hi. I'm trying to make a project. it's suppose to capture the firdt frame and save it as background. then compare it with current frame using background substraction, then detect human using HOG. if human detected, the the frame will recorded.
but when I run the program, it only display current frame in GUI. the background also didn't saved, so the rest process cannot proceed.

here is my code

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Drawing.Imaging;
using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;

namespace TugasAkhir
{
    public partial class Form1 : Form
    {
        Image<Bgr, Byte> _background, _frame, _motion, _detect, _compare;
        Image<Gray, Byte> dif, thresholded, dilasi, erosi, comparegray, comparebw;
        Bitmap erosi1, comparebw2;

        Capture grabber;
        int _width = 320;
        int _height = 240;
        int white_pixel, white_pixel2;
        Boolean status = false;
        int countCap = 1;

        public Form1()
        {
            InitializeComponent();

            _background = new Image<Bgr, Byte>(_width, _height);
            _background = _background.SmoothGaussian(9);
            _frame = new Image<Bgr, Byte>(_width, _height);
            _motion = new Image<Bgr, Byte>(_width, _height);
            _detect = new Image<Bgr, Byte>(_width, _height);
            _compare = new Image<Bgr, Byte>(_width, _height);

            grabber = new Capture(1);
            grabber.FlipHorizontal = true;
            Application.Idle += new EventHandler(InisialisasiCamera);
        }


        void InisialisasiCamera(object sender, EventArgs e)
        {
            _frame = grabber.QueryFrame().PyrUp().Resize(_width, _height, INTER.CV_INTER_AREA);
            captured.Image = _frame;
        }

        void PreProcessing(object sender, EventArgs e)
        {
            dif = new Image<Gray, Byte>(_width, _height);
            Image<Gray, Byte> _framegray = _frame.Convert<Gray, Byte>();
            Image<Gray, Byte> _test = new Image<Gray, Byte>("test.jpg");
            CvInvoke.cvAbsDiff(_test, _framegray, dif);

            thresholded = new Image<Gray, byte>(_width, _height);
            thresholded = dif.ThresholdBinary(new Gray(20), new Gray(255));

            dilasi = new Image<Gray, byte>(_width, _height);
            CvInvoke.cvDilate(thresholded, dilasi, IntPtr.Zero, 2);

            erosi = new Image<Gray, byte>(_width, _height);
            CvInvoke.cvErode(dilasi, erosi, IntPtr.Zero, 2);

            diff.Image = erosi;

            erosi1 = erosi.ToBitmap();
            white_pixel = countPixels(erosi1, Color.FromArgb(255, 255, 255));
            textBox1.Text = white_pixel + " white pixel ";


            int treshmotion = white_pixel;
            treshmotion = 20000;
            if (white_pixel > treshmotion && status == false)
            {
                _motion = grabber.QueryFrame().PyrUp().Resize(_width, _height, INTER.CV_INTER_AREA);
                motion.Image = _motion;

                _detect = _motion.Copy();
                Rectangle[] region;

                using (HOGDescriptor des = new HOGDescriptor())
                {
                    des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());
                    region = des.DetectMultiScale(_motion);
                }

                foreach (Rectangle people in region)
                {
                    _detect.Draw(people, new Bgr(Color.Red), 3);
                }

                CvInvoke.cvAbsDiff(_detect, _motion, _compare);
                comparegray = new Image<Gray, byte>(_width, _height);
                comparegray = _compare.Convert<Gray, Byte>();
                comparebw = new Image<Gray, byte>(_width, _height);
                comparebw = comparegray.ThresholdBinary(new Gray(20), new Gray(255));
                comparebw2 = comparebw.ToBitmap();
                white_pixel2 = countPixels(comparebw2, Color.FromArgb(255, 255, 255));

                if (white_pixel2 > 0)
                {
                    _motion.Save(@"C:\xampp\mysql\captured\capture" + countCap.ToString() + ".jpg");
                    detect.Image = _detect;
                }

                status = true;
                countCap++;
            }

            if (white_pixel <= treshmotion && status == true)
            {
                status = false;
            }
        }

        private int countPixels(Bitmap erosi1, Color white_color)
        {
            int matches = 0;
            for (int y = 0; y < erosi.Height; y++)
            {
                for (int x = 0; x < erosi.Width; x++)
                {
                    if (erosi1.GetPixel(x, y) == white_color)
                    {
                        matches++;
                    }

                }
            }
            return matches;
        }

        private void buttoncapture_Click(object sender, EventArgs e)
        {
            _background = grabber.QueryFrame().PyrUp().Resize(_width, _height, INTER.CV_INTER_AREA);
            _background.Save(@"C:\Users\Lily\Documents\Visual Studio 2010\Projects\TugasAkhir\TugasAkhir\bin\Debug\test.jpg");
            background.Image = _background;
        }


        private void buttondiff_Click(object sender, EventArgs e)
        {
            Application.Idle += PreProcessing;
        }

        private void buttonbg_Click(object sender, EventArgs e)
        {
            background.Image = _background;
        }
    }
}



I'm using visual studio express 2010, emgu 2.2.2, on windows 8 32 bit.
I hope you can help me immediately. I really appreciate every response..
Thank you..
QuestionDisplay graph from selected dropdownlist and radiobutton Pin
Syafiqah Zahirah18-Apr-14 0:43
Syafiqah Zahirah18-Apr-14 0:43 
QuestionCS1525: Invalid expression term '<' error Pin
Member 1075622017-Apr-14 6:12
Member 1075622017-Apr-14 6:12 
AnswerRe: CS1525: Invalid expression term '<' error Pin
Wes Aday17-Apr-14 6:29
professionalWes Aday17-Apr-14 6:29 
GeneralRe: CS1525: Invalid expression term '<' error Pin
OriginalGriff17-Apr-14 8:26
mveOriginalGriff17-Apr-14 8:26 
GeneralRe: CS1525: Invalid expression term '<' error Pin
Richard MacCutchan17-Apr-14 22:16
mveRichard MacCutchan17-Apr-14 22:16 
Questionquestion abot WPF Button Pin
Member 1026763017-Apr-14 3:44
Member 1026763017-Apr-14 3:44 
GeneralRe: question abot WPF Button Pin
Richard MacCutchan17-Apr-14 5:32
mveRichard MacCutchan17-Apr-14 5:32 
GeneralRe: question abot WPF Button Pin
Richard Andrew x6417-Apr-14 8:51
professionalRichard Andrew x6417-Apr-14 8:51 
QuestionHow Do I show Users datail information like Full name,dob etc in a web page stored in database apart from username? Pin
krish099117-Apr-14 1:57
krish099117-Apr-14 1:57 
AnswerRe: How Do I show Users datail information like Full name,dob etc in a web page stored in database apart from username? PinPopular
Pete O'Hanlon17-Apr-14 2:08
mvePete O'Hanlon17-Apr-14 2:08 
AnswerRe: How Do I show Users datail information like Full name,dob etc in a web page stored in database apart from username? Pin
Tom Marvolo Riddle17-Apr-14 2:21
professionalTom Marvolo Riddle17-Apr-14 2:21 
QuestionSee the Activity monitor of employers Pin
Hrishabh Kushwah17-Apr-14 0:56
professionalHrishabh Kushwah17-Apr-14 0:56 
AnswerRe: See the Activity monitor of employers Pin
Wes Aday17-Apr-14 1:51
professionalWes Aday17-Apr-14 1:51 
AnswerRe: See the Activity monitor of employers Pin
Eddy Vluggen17-Apr-14 10:20
professionalEddy Vluggen17-Apr-14 10:20 
Questioni want to know how to compare the two gridviews values Pin
Member 1075542716-Apr-14 21:46
Member 1075542716-Apr-14 21:46 
AnswerRe: i want to know how to compare the two gridviews values Pin
OriginalGriff16-Apr-14 22:04
mveOriginalGriff16-Apr-14 22:04 
AnswerRe: i want to know how to compare the two gridviews values Pin
Chris Quinn16-Apr-14 23:04
Chris Quinn16-Apr-14 23:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.