Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

delphi graphics, connect two pixel colors[red and blue] then draw a line on each point to connect

Posted on 2010-11-28
4
Medium Priority
?
753 Views
Last Modified: 2012-06-27
I have done a few research, but no luck, my bad, can't find any source for this,
does anyone knows how to do this?
please setup your code snippet below.

pixelconnectcolors

thanks
0
Comment
Question by:systan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:ThievingSix
ID: 34227402

procedure FindAndConnect(Graphic: TBitmap; SourceColor, DestColor: TColor);
type
  TRGB32Array = Packed Array[0..(MaxInt div SizeOf(Integer)) - 1] Of Integer;
  PRGB32Array = ^TRGB32Array;
var
  CurrentLine : PRGB32Array;
  X, Y : Integer;
  StartPoint,
  EndPoint : TPoint;
begin
  Graphic.PixelFormat := pf32bit;
  FillChar(StartPoint, SizeOf(TPoint), 0);
  FillChar(EndPoint, SizeOf(TPoint), 0);
  For Y := 0 To Graphic.Height - 1 Do
    begin
    CurrentLine := PRGB32Array(Graphic.Scanline[Y]);
    For X := 0 To Graphic.Width - 1 Do
      begin
      If (CurrentLine^[X] XOR SourceColor) = 0 Then
        begin
        StartPoint := POINT(X, Y);
      end
      Else If (CurrentLine^[X] XOR DestColor) = 0 Then
        begin
        EndPoint := POINT(X, Y);
      end;
    end;
  end;
  Graphic.Canvas.Pen.Color := clBlack;
  Graphic.Canvas.Pen.Width := 1;
  Graphic.Canvas.PenPos := StartPoint;
  Graphic.Canvas.LineTo(EndPoint.X, EndPoint.Y);
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  FindAndConnect(Image1.Picture.Bitmap, clRed, clBlue);
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  Image1.Picture.LoadFromFile('C:\test.bmp');
end;

Open in new window

0
 
LVL 14

Author Comment

by:systan
ID: 34227801
hi ThievingSix;

with that .bmp, It can connect both lines, but if I will use a graphic bmp file pictures, why it can't

I'll close this post after this and answer;
Actually I'm detecting the persons eye with clWhite to clWhite, but didn't work.
Any suggestion?

0
 
LVL 13

Accepted Solution

by:
ThievingSix earned 1000 total points
ID: 34227861
Connecting an eye to an eye is much more complicated than connecting two colors on a white background.

First, this doesn't have a color threshold. The white of a persons eye won't always be clWhite (#FFFFFF). .

Second this doesn't have a range threshold either. So if it see's two white pixels next to each other it will connect those two.

The ideal solution is to find a face detection library.

But for something more simple targeting the  two issues above would be:

1) http://www.delphigroups.info/2/7/299790.html - Color Threshold
2) If you're scanning the image line by line (like the function in the last post) on a face, you'll notice color --> white --> color --> black --> color --> white --> color --> white --> color --> black --> color --> white --> color. In this fashion you would detect this sequence in the scanline over the entire image width. You would mark the scanline and if you notice a group of scanlines that are more marked than not you know where the eye's are.
0
 
LVL 14

Author Closing Comment

by:systan
ID: 34227914
Thanks
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question