Skip to content

Commit

Permalink
added MX file tools and FaceFinder
Browse files Browse the repository at this point in the history
  • Loading branch information
flip phillips committed Apr 24, 2018
1 parent 81de18a commit e0135d5
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 64 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@

## [Unreleased changes]

### Added
- `NewKernelEvaluate`
- `GetSymbolsDefinedInMX`
- `FindFaceImages`

### Changed
- minor housekeeping


## [0.1.14] - 2018-04-24

### Added
Expand Down
4 changes: 2 additions & 2 deletions Development/Image.nb
Git LFS file not shown
4 changes: 2 additions & 2 deletions Development/Introspection.nb
Git LFS file not shown
5 changes: 0 additions & 5 deletions FPTools/Data.wl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,3 @@ ImportAsDataset[f_,

True,
Dataset[raw]]]

(* Maybe should be split out as 'Statistics' some day *)
UnitizedGaussianPDF[\[Mu]_, \[Sigma]_] := Module[{pdf},
pdf = PDF[NormalDistribution[\[Mu], \[Sigma]]];
Evaluate[pdf[#]/ pdf[\[Mu]]] &]
12 changes: 12 additions & 0 deletions FPTools/Image.wl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ BlurFaces[i_Image,OptionsPattern[]]:=Module[{how,fboxs,polys,ff},
HighlightImage[i, {"Blur", polys}],
HighlightImage[i, {{"Blur",OptionValue["FilterRadius"]}, polys}]]]

FindFaceImages[img_, scale_: 1.0, opts : OptionsPattern[FindFaces]] :=
Module[{scaledRectangle, r, r2},
r = FindFaces[img, opts];

scaledRectangle[r_Rectangle, s_] :=
r /. x_ :>
Rectangle[x[[1]] - (Abs[x[[1]] - x[[2]]]/2) (s - 1),
x[[2]] + (Abs[x[[1]] - x[[2]]]/2) (s - 1)];

r2 = scaledRectangle[#, scale] & /@ r;
ImageCrop[HighlightImage[img, {White, #}, "Remove"]] & /@ r2]


(* ::Subsection:: *)
(*Alpha Channel*)
Expand Down
54 changes: 50 additions & 4 deletions FPTools/Introspection.wl
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
(* ::Package:: *)

(*
* Original Spelunk code by Simon Woods.
* http://mathematica.stackexchange.com/a/15948
*)
(* ::Subsection:: *)
(*Spelunk*)


(* ::Text:: *)
(* Original Spelunk code by Simon Woods. *)
(*http://mathematica.stackexchange.com/a/15948*)


defboxes[symbol_Symbol] := Hold[symbol] /. _[sym_] :>
If[MemberQ[Attributes[sym], Locked], "Locked",
Expand Down Expand Up @@ -50,13 +54,20 @@ processsymbol[a_, b_] := Module[{db},
DefaultBaseStyle -> {"Input"}, Appearance->"None", Evaluator -> Automatic]
]]


Spelunk[symbol_Symbol] := CellPrint[fancydefinition[symbol]];


Spelunk[s_String] := CellPrint[fancydefinition[#] &@ToExpression[s, InputForm, Unevaluated]];


SetAttributes[{defboxes, fancydefinition, Spelunk}, HoldFirst]


(* ::Subsection:: *)
(*Properties*)


PropertiesAvailability[obj_] := Module[{plist,evals,missing,not},
plist=obj["Properties"];
evals=Quiet[Check[obj[#],Missing[#]]&/@plist];
Expand All @@ -77,3 +88,38 @@ PropertiesDataset[thing_] := Module[{t, u},


SetAttributes[{PropertiesAvailability, PropertiesDataset}, HoldFirst]


(* ::Subsection:: *)
(*Dumpsave*)


(* ::Text:: *)
(*https://mathematica.stackexchange.com/questions/25027/dumpsave-for-the-forgetful*)


(* newKernelEvaluate starts a fresh auxiliary kernel, evaluates expr, *)
(* quits auxiliary kernel, and returns the result of evaluation. *)

Attributes[NewKernelEvaluate] = HoldAll;
NewKernelEvaluate[expr_] := Module[
{link, result},
link = LinkLaunch[First@$CommandLine <> " -mathlink -noprompt"];
LinkWrite[link, Unevaluated@EvaluatePacket@expr];
result = LinkRead@link;
LinkClose@link;
Replace[result, ReturnPacket@x_ :> x]
];


GetSymbolsDefinedInMX[mxfile_] := Module[
{tag},
With[{mymxfile=mxfile},
NewKernelEvaluate[
Block[
{$NewSymbol=Sow[#2<>#1, tag]&},
Reap[Get[mymxfile],tag][[2]]
]
]
]
];
110 changes: 64 additions & 46 deletions FPTools/PacletInfo.m
Original file line number Diff line number Diff line change
@@ -1,48 +1,66 @@
Paclet[
Name -> "FPTools",
Description -> "Tools for introspection, debugging, syntatic sugar, etc.",
Creator -> "Flip Phillips <[email protected]>",
Publisher -> "Skidmore Vision Lab",
Copyright -> "©2018- Flip Phillips & Misc Contributors",
License -> "MIT",
Version -> "0.1.14",
BuildNumber -> "124",
MathematicaVersion -> "11.2+",
URL -> "https://github.com/flipphillips/FPTools",
Thumbnail -> "Documentation/icon.png",
Loading -> Automatic,
Extensions -> {
{ "Documentation",
MainPage -> "Guides/FPTools",
Language -> "English"},
{ "Kernel",
Symbols -> {
"FPTools`$FPToolsVersion","FPTools`$FPToolsDebug",

"FPTools`Spelunk","FPTools`PropertiesAvailability","FPTools`PropertiesDataset",

"FPTools`EntityPropertiesDataset",
"FPTools`ConceptBroaden","FPTools`ConceptDistance","FPTools`ConceptDepth",

"FPTools`RectangleToDisk",

"FPTools`ImageIdentifyFP","FPTools`BlurFaces","FPTools`AddAlphaChannel",
"FPTools`LensDistortPoint", "FPTools`LensDistortionCorrection",
"FPTools`$MachineAddressesExternal",

"FPTools`ApplyIf",

"FPTools`VersionInformation",
"FPTools`VersionString","FPTools`VersionBuildString",
"FPTools`VersionWriteInformation","FPTools`VersionBumpBuild",
"FPTools`UpdatePacletFile",

"FPTools`ImportAsDataset", "FPTools`FindZeroCrossings","FPTools`UnitizedGaussianPDF",

"FPTools`$FFMpegPath", "FPTools`ImportMP4Frame", "FPTools`ImportMP4Frames", "FPTools`ImportWebFrame",

"FPTools`GARepopulate","FPTools`GAMutate","FPTools`GACrossover"
},
Context -> {"FPTools`"} }
}
Name -> "FPTools",
Description -> "Tools for introspection, debugging, syntatic sugar, etc.",
Creator -> "Flip Phillips <[email protected]>",
Publisher -> "Skidmore Vision Lab",
Copyright -> "©2018- Flip Phillips & Misc Contributors",
License -> "MIT",
Version -> "0.1.15",
BuildNumber -> "129",
MathematicaVersion -> "11.2+",
URL -> "https://github.com/flipphillips/FPTools",
Thumbnail -> "Documentation/icon.png",
Loading -> Automatic,
Extensions -> {
{ "Documentation",
MainPage -> "Guides/FPTools",
Language -> "English"},
{ "Kernel",
Symbols -> {
(* globals *)
"FPTools`$FPToolsVersion","FPTools`$FPToolsDebug",

(* data *)
"FPTools`ImportAsDataset",

(* Entity *)
"FPTools`EntityPropertiesDataset",
"FPTools`ConceptBroaden","FPTools`ConceptDistance","FPTools`ConceptDepth",

(* GAs *)
"FPTools`GARepopulate","FPTools`GAMutate","FPTools`GACrossover",

(* Graphics *)
"FPTools`RectangleToDisk",

(* Image *)
"FPTools`ImageIdentifyFP",
"FPTools`BlurFaces","FPTools`FindFaceImages",
"FPTools`AddAlphaChannel",
"FPTools`LensDistortPoint", "FPTools`LensDistortionCorrection",
(* ffmpeg *)
"FPTools`$FFMpegPath", "FPTools`ImportMP4Frame", "FPTools`ImportMP4Frames", "FPTools`ImportWebFrame",

(* internet *)
"FPTools`$MachineAddressesExternal",

(* introspection *)
"FPTools`Spelunk","FPTools`PropertiesAvailability","FPTools`PropertiesDataset",
"FPTools`NewKernelEvaluate","FPTools`GetSymbolsDefinedInMX",

(* signals *)
"FPTools`FindZeroCrossings","FPTools`UnitizedGaussianPDF",

(* sugar *)
"FPTools`ApplyIf",

(* versioning *)
"FPTools`VersionInformation",
"FPTools`VersionString","FPTools`VersionBuildString",
"FPTools`VersionWriteInformation","FPTools`VersionBumpBuild",
"FPTools`UpdatePacletFile"

},
Context -> {"FPTools`"} }
}
]
5 changes: 5 additions & 0 deletions FPTools/Signals.wl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ FindZeroCrossings[l_List] := Module[{t, u, v},
v = SplitBy[u, First];(*Group into runs of+and-values*){Most[Max[#[[All, 2]]] & /@ v],
Rest[Min[#[[All, 2]]] & /@ v]} // Transpose]


(* Maybe should be split out as 'Statistics' some day *)
UnitizedGaussianPDF[\[Mu]_, \[Sigma]_] := Module[{pdf},
pdf = PDF[NormalDistribution[\[Mu], \[Sigma]]];
Evaluate[pdf[#]/ pdf[\[Mu]]] &]
4 changes: 3 additions & 1 deletion FPTools/Usage.wl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ $FPToolsDebug::usage = "$FPToolsDebug let's us know if the package was built wit
Spelunk::usage = "Spelunk[symbol] will discover the definition of symbol. Underlined symbols in the output are clickable.";
PropertiesAvailability::usage = "PropertiesAvailability[object] returns the {available, unavailable} properties for an object.";
PropertiesDataset::usage = "PropertiesDataset[object] returns a TableForm of the available properties for object.";

NewKernelEvaluate::usage = "NewKernelEvaluate[expr] evaluates expr in a fresh, clean kernel and returns the result."
GetSymbolsDefinedInMX::usage = "GetSymbolsDefinedInMX[mxfile] returns a list of symbols defined in mxfile."

(* ::Section:: *)
(*Entity*)
Expand All @@ -34,6 +35,7 @@ ConceptDepth::usage = "ConceptDepth[entity] computes the distance to the root of

ImageIdentifyFP::usage = "ImageIdentifyFP[image,{n}] does the standard image identify returnig n (default 5) items and its probabilities.";
BlurFaces::usage = "BlurFaces[image] blurs faces in image. Options include Method (Box,Disk,Outline,Eyes,FaceParts) and FilterRadius.";
FindFaceImages::usage = "FindFaceImages[image,scale] finds images in an image, scaling the returned image by scale (default 1). Larger values provide more context, smaller less.";
AddAlphaChannel::usage = "AddAlphaChannel[image] adds a unity alpha channel to image.";

$FFMpegPath::usage = "$FFMpegPath is the path to the `ffmpeg` executable.";
Expand Down
12 changes: 11 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
## Introspection
- combine the concept and generic 'object' property tools
- There is a bug in the Dataset display that breaks when you ask a lot of things about BoundaryRegions.
- Seems to happen when the suggestion bar is enabled.

## More
- Migrate Disk/Rectangle stuff
Expand All @@ -16,4 +17,13 @@
## Data
- fork off `ffmpeg` stuff.
- enhance above.
- check for executable
- add ffprobe stuff

## Meta

### Adding new function
- if new file add to `FPTools.wl`
- add to `PacletInfo.m`
- add to `Usage.wl`
- add to Documentation
- add to test suite?
6 changes: 3 additions & 3 deletions version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "FPTools",
"major_version": 0,
"minor_version": 1,
"revision_number": 14,
"build_number": 125,
"date": "Tue Apr 24 11:31:10 EDT 2018"
"revision_number": 15,
"build_number": 130,
"date": "Tue Apr 24 15:24:05 EDT 2018"
}

0 comments on commit e0135d5

Please sign in to comment.