This project is read-only.

marker problem

Feb 25, 2010 at 10:59 PM

hi guys,

congrats on the project, i love the idea. im pretty well-versed in image processing, not so much in c#. i got some fun ideas and could be a decent contribution to the subject, but first i need a helping hand to get into coding ;)

So i found this website tonight, downloaded the code and tried to make my own simple application basing on provided classes but im stuck with the markers. When the radius is small no marker change event happens but if its bigger it seems whole picture is marked. Whys that?

Im probably just not getting sth, its pretty late in my country, but im dying to know what im doing wrong, heres the code

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 TouchlessLib;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        TouchlessMgr touch = new TouchlessMgr();
        Bitmap overlay;
        
        

        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap c = touch.CurrentCamera.GetCurrentImage();
            pictureBox1.BackgroundImage = c;
            button1.Enabled = false;
            
        }
        Bitmap obraz = new Bitmap(100, 100);
        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (Camera c in touch.Cameras)
            {
                if (c != null)
                {
                    touch.CurrentCamera = c;
                    c.OnImageCaptured += new EventHandler<CameraEventArgs>(c_OnImageCaptured);
                    overlay = new Bitmap(c.CaptureWidth, c.CaptureHeight);
                    overlay.MakeTransparent();
                    break;
            
                }
            }
            pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
        }

        

        void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            lock (this)
            {
                if (_b != null)
                {
                    e.Graphics.DrawImageUnscaledAndClipped(_b, pictureBox1.ClientRectangle);
                    e.Graphics.DrawImageUnscaledAndClipped(overlay, pictureBox1.ClientRectangle);
                    
                }
            }

        }
        Bitmap _b;
        void c_OnImageCaptured(object sender, CameraEventArgs e)
        {
            if (button1.Enabled)
            {
                _b = e.Image;
                pictureBox1.Invalidate();
               
               
            }
        }

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            
            
        }
        
        void m_OnChange(object sender, MarkerEventArgs e)
        {
            
            lock (this)
            {
                if (e.EventData.Present)
               {
          
                    overlay.SetPixel(e.EventData.X, e.EventData.Y, Color.Black);
                    
                }
            }
            
                   // Cursor.Position = new System.Drawing.Point((int)(e.EventData.X), (int)(e.EventData.Y));
        }
       
        int mousedownx, mousedowny, radius;
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            mousedownx = e.X;
            mousedowny = e.Y;
        }
         
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            radius = (int)(Math.Sqrt(Math.Pow((mousedownx - e.X), 2) + Math.Pow((mousedowny - e.Y), 2)))/2;
            textBox1.Text = radius.ToString();


            Marker m = touch.AddMarker("marker", (Bitmap)pictureBox1.BackgroundImage, new Point(e.X, e.Y), radius);
            m.Highlight = true;
            m.Threshold = 4;
            m.OnChange += new EventHandler<MarkerEventArgs>(m_OnChange);
            button1.Enabled = true;
            texttres.Text = m.Threshold.ToString();
        }
    }
}

cheers!

Feb 25, 2010 at 11:09 PM

At first glance it looks like you are centering the AddMarker circle around the mouseup point, maybe that doesn't match how you are actually clicking and dragging in your app's interface. Try drawing that circle on your overlay so you know what area of the image you are using to train your marker. Good luck!

- Mike

Feb 26, 2010 at 12:09 AM

the problem must be somewhere else because at first i used mouseclick event and constant radius. Can you help?

Feb 26, 2010 at 12:43 AM

allright, its all about different screen/picture/webcam resolutions