ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Semi-transparent Layers with non-transparent border?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

934 Posts

Posted - Nov 05 2022 :  14:15:55  Show Profile  Reply
I mark detected faces with semi-transparent filled Layers:



However, it seems that the semi-transparent Layers also make semi-transparent borders, so the visibility of the red borders is reduced:

procedure TformMain.mExtractFacesClick(Sender: TObject);
begin
  ImageEnViewPixelEditor.MouseInteractLayers := [mlMoveLayers, mlResizeLayers];
  // Layers cannot be dragged beyond the background layer:
  ImageEnViewPixelEditor.LayerOptions := ImageEnViewPixelEditor.LayerOptions + [loPreventOutOfBounds];

  // create objectsFinder:
  var objectsFinder := IEVisionLib.createObjectsFinder();
  // following haar parameters may vary by image content:
  objectsFinder.setDivisor(1);
  objectsFinder.setHaarMinNeighbors(4);
  //objectsFinder.setHaarScaleFactor(1.2);
  // Add classifiers:
  objectsFinder.addClassifier('face detector 1', IEVisionLib.createCascadeClassifier(IEVC_FRONTAL_FACE_DEFAULT));
  objectsFinder.addClassifier('face detector 2', IEVisionLib.createCascadeClassifier(IEVC_FRONTAL_FACE_ALT_TREE));
  objectsFinder.addClassifier('face detector 3', IEVisionLib.createCascadeClassifier(IEVC_FRONTAL_FACE_ALT));
  objectsFinder.addClassifier('face detector 4', IEVisionLib.createCascadeClassifier(IEVC_FRONTAL_FACE_ALT_2));
  objectsFinder.addClassifier('face detector 5', IEVisionLib.createCascadeClassifier(IEVC_PROFILE_FACE));
  CodeSite.Send('TformMain.mExtractFacesClick: 1');
  // Find Faces in image:
  objectsFinder.findIn(ImageEnViewPixelEditor.IEBitmap.GetIEVisionImage());
  var rects := objectsFinder.mergeAllRects(); // merge intersecting rectangles
  CodeSite.Send('TformMain.mExtractFacesClick: 2');
  // Draw rects to image:
  ImageEnViewPixelEditor.LayersClear(False);
  var r: TIEVisionRect;
  for var i := 0 to rects.size() - 1 do
  begin
    r := rects.getRect(i);
    //with ImageEnViewPixelEditor.IEBitmap.Canvas do
    begin
      {Pen.Width := 2;
      Pen.Color := clRed;
      Brush.Style := bsClear;
      Rectangle(r.x, r.y, r.x + r.width, r.y + r.width);}

      var ThisLayer := ImageEnViewPixelEditor.LayersAdd(iesRectangle, Rect(r.x, r.y, r.x + r.width, r.y + r.height),
        clRed, 2, clYellow);
      ImageEnViewPixelEditor.Layers[ThisLayer].Visible := True;
      ImageEnViewPixelEditor.Layers[ThisLayer].VisibleBox := True;
      ImageEnViewPixelEditor.Layers[ThisLayer].Transparency := 64;
      ImageEnViewPixelEditor.Layers[ThisLayer].Tag := FFaceLayer;
      ImageEnViewPixelEditor.Layers[ThisLayer].BorderColor := clRed;
      ImageEnViewPixelEditor.Layers[ThisLayer].BorderWidth := 2;
    end;
  end;
  ImageEnViewPixelEditor.Update;
  CodeSite.Send('TformMain.mExtractFacesClick: 3');
end;


So is there a way to make the borders of the layers NON-TRANSPARENT (to increase their visibility) while leaving the Layers still semi-transparent?

BTW, I don't want to paint rectangles directly on the image - that's why I use only Layers to mark the faces. A possible workaround could be to duplicate the background layer and paint the rectangles on that duplicate layer. But that would complicate things enormously when having to move or resize the layers, so I would prefer to have layers with non-transparent borders - if that is possible.

BTW2, anyone will have noticed that the two rectangles on Mr. B.G. completely intersect and should be merged. So this seems to be an issue that should also be resolved.

PeterPanino

934 Posts

Posted - Nov 05 2022 :  17:13:34  Show Profile  Reply
I tried this approach:

for var i := 0 to rects.size() - 1 do
begin
  r := rects.getRect(i);
  var bm := TIEBitmap.Create;
  cxImageListLarge.GetImage(11, bm.VclBitmap); // semi-transparent mono-color PNG image
  var ThisLayer := ImageEnViewPixelEditor.LayersAdd(bm);
  ImageEnViewPixelEditor.Layers[ThisLayer].LayerRect := Rect(r.x, r.y, r.x + r.width, r.y + r.height);
  ImageEnViewPixelEditor.Layers[ThisLayer].Visible := True;
  ImageEnViewPixelEditor.Layers[ThisLayer].VisibleBox := True;;
  ImageEnViewPixelEditor.Layers[ThisLayer].Tag := FFaceLayer;
  ImageEnViewPixelEditor.Layers[ThisLayer].BorderColor := clRed;
  ImageEnViewPixelEditor.Layers[ThisLayer].BorderWidth := 2;
  bm.Free;
end;


The Layers are created correctly, but they have no visible image and no visible border.
Go to Top of Page

PeterPanino

934 Posts

Posted - Nov 05 2022 :  17:51:06  Show Profile  Reply
Another approach is this one:

for var i := 0 to rects.size() - 1 do
begin
  r := rects.getRect(i);
  var ThisLayer := ImageEnViewPixelEditor.LayersAdd(iesRectangle, Rect(r.x, r.y, r.x + r.width, r.y + r.height),
    clRed, 2, clYellow);    
  ImageEnViewPixelEditor.Layers[ThisLayer].Visible := True;
  ImageEnViewPixelEditor.Layers[ThisLayer].VisibleBox := True;
  ImageEnViewPixelEditor.Layers[ThisLayer].Operation := ielAverage;
  ImageEnViewPixelEditor.Layers[ThisLayer].Tag := FFaceLayer;
  ImageEnViewPixelEditor.Layers[ThisLayer].BorderColor := clRed;
  ImageEnViewPixelEditor.Layers[ThisLayer].BorderWidth := 2;
end;




It is not optimal, but it is still better than the first one.
Go to Top of Page

PeterPanino

934 Posts

Posted - Nov 05 2022 :  18:03:11  Show Profile  Reply
When using $0093FFFF instead of clYellow, it is even better:

Go to Top of Page

xequte

38684 Posts

Posted - Nov 06 2022 :  18:18:02  Show Profile  Reply
Hi

You can use FillOpacity to specify a different transparency for the fill than the the border. See the example at:

http://www.imageen.com/help/TIELayer.FillOpacity.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

934 Posts

Posted - Nov 07 2022 :  04:58:47  Show Profile  Reply
Hi Nigel,

Thank you, that works perfectly. ImageEn has a solution for everything.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: