Message Boards Message Boards

0
|
7935 Views
|
7 Replies
|
9 Total Likes
View groups...
Share
Share this post:

Confused 'Old School' programmer (and Wolfram Programming Cloud)

Posted 10 years ago

Just started looking at Wolfram Alpha so apologise in advance for my ignorance (I am familiary with traditional languages like C, JavaScript but also a bit of XSLT and Lisp).

Anyway, I thought I'd try to write a program that would allow a user to supply a URL of an image and then it would count the number of faces it found in the picture - thinking I should be able to do this in half a dozen lines of code.

Well, I fall at the first hurdle !!! I try using InputFileld to capture a URL from the user - the textbox appears fine but I can't seem to access the value entered i.e. pictureurl = InputField[] just doesn't set pictureurl !?!?!?

Any ideas what I'm doing wrong?

Also, on a seperate note - do I need to prefix every line with 'CloundDeploy' in order to 'save it' to the cloud - this seems crazy to me who is more used to the develop -> compile -> deploy way of coding.

All hints/tips will be gratefully received.

Jim

POSTED BY: Jim MacAulay
7 Replies

Give the following a try. The image is only updated when the button is clicked. Presumably the Dynamic is attempting to continuously update things even though there is no change in the input URL. The following works, mainly because the update of the image is user controlled--but of course it does not explain the problems you are having with the original code... I will think more to see if I can explain the issue (though it is likely covered in the documentation for advanced Dynamic)

ClearAll@interface
interface[] :=
 DynamicModule[{url = "", y = Graphics[{}]},
  Grid[{{
     "Paste your URL below:"}, {
     Row[{Button["Click", y = getFacesFromUrl[url]], Spacer[10],
       InputField[Dynamic@url, String, ImageSize -> 750]}]},
    {
     Dynamic@y}
    },
   FrameStyle -> LightGray, Frame -> True, Alignment -> Left]]
POSTED BY: David Reiss

Code retyped...

ClearAll@getFacesFromUrl
getFacesFromUrl[url:Null|""]:=""
getFacesFromUrl[url_String]:=Module[{img,facesBox},
    img=Quiet@Check[Import[url],Return@"Error loading URL"];
    If[Head@img=!=Image,Return@"Not an Image URL"];
    facesBox=FindFaces[img];
    Rasterize@Show[img,Graphics[{EdgeForm[{Red,Thick}],Opacity[0],Rectangle@@@facesBox}],ImageSize-> 700]
]

(*THIS DYNAMIC PART CODE HAS SOME BUG IN MY MATHEMATICA 9
MY NOTEBOOK GET INTO A LOOP WHEN URL IS INSERTED AND ENTER IS PRESSED
THE MSG IS "FORMATTING DYNAMIC CONTENT"*)
ClearAll@interface
interface[]:=DynamicModule[{url=""},
    Grid[{
         {"Paste your URL below:"}
        ,{InputField[Dynamic@url,String,ImageSize->700]}
        ,{Dynamic@getFacesFromUrl[url]}
       }
       ,FrameStyle->LightGray
       ,Frame->True
       ,Alignment->Left
       ]
]
interface[]

Example of Face URL to past into InputField

Notebook Attached

Attachments:
POSTED BY: Rodrigo Murta

@David Yes!.. I know. I was still polishing it when it crashed.

Nice try with TextRecognize :)

POSTED BY: Rodrigo Murta

Just a quick comment: the Dynamic in front of the Column is probably not needed.

Alas, I tried to extract your code using TextRecognize on the image of your code, but only got gibberish...

POSTED BY: David Reiss

@David, some clue on this Dynamic bug? What I'm doing wrong?

POSTED BY: Rodrigo Murta

Hi Jim. I was working in a response for your, when my notebook crashed/froze. Here is a print of the code, no time to retype now. It was working fine, but I lost the image url that I was testing.

enter image description here

enter image description here

POSTED BY: Rodrigo Murta

Rodrigo, nice job, any chance you will post code as code - not as image - or attach a notebook?

POSTED BY: Sam Carrettie
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract