Forum Archive

Request for an App

ihf

I am in need of an app which can find the area of a space that is represented by a jpeg where at least one measurement is known. For example, I have a floor plan of an apt that purports to be a certain area. The floor plan has room sizes shown. I want to be able to simply enter one measurement to get the scale ratio and then trace the plan to find the area. This is easy to do using a program such as Adobe Acrobat Pro on a desktop but I have not seen anything similar for IOS (or Android). If someone knows of such a program, please let me know. It seems as if this should not be overly difficult to do using Pythonista and I could make it my project to write it but I fear that may take awhile given my (rusty) python skills not to mention the UI using Pythonista. If someone has the time and inclination, I (and I think others) would be most grateful for such an app/script.

Webmaster4o

So, you want to have an image, input one dimension for it, and get the area, based on scaling at that ratio? Or is it more complicated than this?

TutorialDoctor

The best app on the app store for CAD is Touchdraw

ihf

@Webmaster40 Precisely.
@TutorialDoctor I believe that Touchdraw is more about drawing the floor plan where I am starting with a floorplan and merely want to compute the area of a (non rectangular) figure. For extra credit, it would be nice to be able to draw around the perimeter and then around areas to delete from the area calculation but that is less essential.

TutorialDoctor

It has that feature inside. You can scale irregular shapes and it computes the area dynamically. I can take a screenshot. Give me a second.

ihf

@TutorialDoctor From a jpeg, as opposed to something that was created using TouchDraw?

TutorialDoctor

I suppose if you import the jpeg and trace it using the pen tool, that would be the faster way. To compute the area dynamically you just add a small bit of code to the traced object. Your case is very specific, but I think it should work for your purposes. I am working on that screenshot now.

Seems they have it documented:

http://docs.elevenworks.com/display/TDIPAD/Calculating+Area

ihf

@TutorialDoctor Unless I am mistaken, the doc shows how to compute area of a figure you have drawn in the app. Perhaps there is a way to import a JPEG and draw on it, but I didn't see that. Yes, my requirement is fairly specific but, I think, not unique. People often publish a floor plan as part of a house or apartment listing and assert that the area is x when in fact a measurement of the plan (or the space itself) shows otherwise.

TutorialDoctor

Yes, you can import a photo and draw on it. You can also set the scale too.

An extended solution would be to trace the image using a program like Adobe Illustrator (the live trace feature) which converts an image to SVG. From there you import the image into Touchdraw and add the formula to the shape.

This all depends on how well the image is traced in Illustrator (Inkscape has a similar though buggier version of this).

I don't currently know of any quicker solutions though. Perhaps someone else may.

Also, you can set the length of a side and the scale will adjust accordingly. I have to see if I can remember how to do this first though:

Here is how to do dimensioning

I have an app called MyMeasures also.

https://itunes.apple.com/us/app/my-measures-pro/id325962257?mt=8

Phuket2

@ihf , I am not trying to be the gringe of Christmas.but I think what you are looking for is impractical. Maybe not, but my 2 cents worth is that depending on what country you are in a house/condo Sqm is calculated differently. Example in Australia with a condo, if you have a car space that is included in the advertised sqm. Totally legal. But depending on the type of title, a balcony maybe included or excluded from the advertised sqm. So that's just a few gotchas. You would also assume your floor plan is too scale. But unless you have the a0 paper plan from the architect, reproductions can get so bad on scaling. They will be relative, mostly. But to try an accurately measure them digitally in my opinion not easy. If from the drawings you have, you can put a scale ruler on top of it and get good readings, maybe you have a chance. But the practical side of it is not easy

Webmaster4o

This is incredibly easy to do with Pythonista if that's what you're asking for.

from PIL import Image
import photos

im = photos.pick_image() # Load the image with whatever method you'd like

dimension = 1 if raw_input("Which dimension are you inputting?\n").lower() == "width" else 0

dimension_value = int(raw_input("Value: "))

"""
We can use the proportion:

image_width       your_width
------------ = -----------------
image_height   unknown_dimension

and with this, cross-multiply"""

if dimension: # We're solving for the height
    print im.size[1]*dimension_value / float(im.size[0])
else:
    print im.size[0]*dimension_value / float(im.size[1])

If this isn't what you're looking for, please elaborate. If my code is wrong, tell me, I wrote it without testing :)

P. S. @Phuket2 it's "grinch" ;)

ihf

@Webmaster4o Thank you. I think this is a wonderful start but what I want to be able to do is draw a straight line on the jpeg (e.g. one side of a room) and input what the drawing says that is in feet. Then I want to be able to trace the perimeter of the entire plan) and get the area in sq ft. In Adobe Acrobat this is done by measuring one known dimension and setting the scale ratio so that, for example, 1.2in = 14 ft (or whatever the plan says). Then I click at any place on the jpeg and a straight line is drawn until I close the polygon and the area in sq ft is displayed.

Webmaster4o

Right. This is harder, but still doable with proportions and Pythagorean theorem. Use the distance formula (which is really just Pythagorean theorem rewritten) to find diagonal distance between 2 points:
, then use that as a proportion to the known distance.

JonB

is your goal for something that auto-detects walls and computes area? Or you set scale, thrn manually trace, or perhaps set a series of corner points using a zoomed view for accuracy?

ihf

The latter. If still unclear: I want to do in Pythonista what is shown in this video using Acrobat Pro. (https://www.youtube.com/watch?v=5Ra4kgOGq9Q)

JonB

and do you want to aquire your image via camera? or scan? i.e, do we need to "flatten" image and take out perspective errors?

https://www.mathsisfun.com/geometry/area-irregular-polygons.html is a good summary of how to calculate area from a set of ordered coordinates. I would probably do everything in pixel units, then scale the area by (ft/pixel)**2 at the end.

ihf

No need to flatten anything as I will be starting with floor plans. I have no trouble with the math involved. It's really the Pythonista UI (getting the points, drawing the lines on the image, recognizing and closing the polygon. I'm sure that all of this is easy for someone (not me) who has used the UI. The calculations are really quite straightforward. I suppose it will be a good learning experience :-)

ccc

@ihf Make a new repo, name it RoomAreaFinder and add a jpg or png file of a floor plan. Look at https://github.com/humberry/photo_text and get enough code to grab your floor plan from the camera roll and display it within a Pythonista UI. If you then provide the URL to that repo, we can provide improvement suggestions until you have your app.

Webmaster4o

@ihf I agree with @ccc. Why don't you write an app that's purely text-based so that you have all the math in place. Then, post back here once you've got that done and we'll help with the UI.

ihf

Sounds like a plan. Thanks guys!

ihf

OK, I created (my first) git repo (https://github.com/ifuchs/RoomAreaFinder) using Stash. You will see the functions that are now largely stubs that get the scale line endpoints and the polygon vertices all from a jpg. I uploaded a sample floor plan. Please excuse the python. Any help for acquiring the coordinates would be much appreciated.

P.S. It just occurred to me that I also need another function that is called by getPolygonVertices to determine when the polygon is closed...have to figure out how to do that.

Phuket2

@ihf , this may sound stupid, but it's ok, I am used to making stupid remarks. But as a quick and dirty idea, if you can place rects on the image and name them like bedroom1 etc. you could add up the total sqm as well as individual named areas. My idea being that a room/area might consist or more that one named rect. Ok, if there is a lot of angles it's not great. But it's also not that bad. With multiple rects of differing sizes you could get most of it. But yes polygons are better

ihf

@Phuket2 Not a stupid idea at all but I really need to be able to trace the outline to get the total sq. ft. and not just the room outlines. I need to be able to compare the total to the one that is asserted. As you can see, the polygon area calculation is quite simple. Now I just need a UI that captures the points.

Phuket2

@ihf , do you have a pic of a plan that's ok to share? Whilst I am not great on the math, I used to draw 2d kitchen plans as a job many years ago. That was on a Mac plus. I was using Mac Draft. I think from Microspot at the time, a U.K. Company. But I have dealt with many plans in my life span. It's the only encouraging thing about getting old 😱

ihf

I added one to the git.

Phuket2

@ihf , ok a little bit more exotic than the normal floor plan. But if the red rectangle around the floor plan below is the sqm then minus all the yellow rectangles. If all was to scale in the ui, would be very close. Look, just trying to help. Normally floor plans are just a series of rectangles more often than not. Just about getting the scale right. I can't remember clearly, but I think for kitchens (1 room) we did 25:1. I think for a house it was more like 250:1

ihf

I appreciate your help but I really need the square footage of the full outline as that is what real estate listing show. Also some of the floor plans I am dealing with would not be amenable to this approach as they have some less than right angles in them.

Phuket2

@ihf , ok no problems. I understand. Was just trying to make the problem similar to solve. But I had fun contributing 😎

MartinPacker

Another approach - one used to estimate Pi - is to generate random points and see if they're inside or outside the building.

The proportion that are to those that aren't can be used with the overall scene's area.

ihf

Thanks, that's interesting but given that the jpg may contain other extraneous items, I think it would be better to outline the area of interest. The calculation part of the script is in the git. What I need is help with the UI.

MartinPacker

Could you colour flood fill from the outside and then test pixels? You might need to eliminate e.g. the compass in your example. Though I doubt it adds much to the inaccuracy.

ihf

Is there something wrong with the approach of entering vertices by touching them?

Phuket2

@ihf , I think you are getting frustrated now. I understand why 🤐

But I am sure guys here can help with what you need. If you look at the path demo in the examples folder, pretty sure it's what you are looking for with a ui. Not something I can do competently, so I will we another one answer. But I think that's on the right track

ihf

I was concerned that the creative alternative suggestions might be because what I am envisioning is somehow more difficult than it seems. I am pretty sure that collecting the polygon's vertices' coordinates and the scale line can't be difficult (at least for someone who is adept at using the Pythonista UI). Figuring out if the polygon has been closed without actually touching (precisely) the initial vertex ought to be doable by looking at the distance and simply prompting for whether this closes the outline. Adding the ability to move the vertices to fine tune is something that could be added later.

Phuket2

@ihf , I don't know about the native graphic support on iOS. But in 1984 it was pretty easy to program with polygons in c. It was what set the Mac apart. Was all in the Mac toolbox. The Mac toolbox from memory was just an exception call to the 68000 Motorola series processors. That exception was caught and looked up to see if it was a toolbox call.
Anyway enough reminiscing, if it was easy to do in 1984, should be very easy today. But the functions did not just work on a singular polygon, worked on multiple polygons. Was so cool for its time

Webmaster4o

@ihf

@MartinPacker 's method would still allow for the same input, and it would work nicely. See the Monte Carlo method.

JonB

I added a very simple ui as a pull req.
https://github.com/jsbain/RoomAreaFinder

Draw the first line, then set the scale in the upper Left corner until the line length matches whatever the real length is, in whatever units you want. Then add vertices (click, or drag then release). Area is shown, though won't be accurate until the path is almost closed.

Some obvious improvements need to be made: magnifying zoom type effect when dragging, ability to grab and move existing points, slider for scale, perhaps pan/zoom for small devices.

ihf

@JonB My hat is off to you! It is already useful. With the improvements, I think this would be a publishable app. Many thanks!

ihf

@JonB I see you initially set scale to 0.08. What is the origin of that value? My thought was to set scale by initially touching 2 points that define a known length and then entering that length.

Phuket2

@ihf , sorry if I frustrated your efforts. But very happy to see you got a solution , or a least on the road to one.

JonB

I set the scale based on what looked about right on my ipad in landscape. it was slightly easier to implement this way, as it did not require an additional mode -- just draw, then set scale whenever it is convienent. for instance, you might find the initial points were not that accurate, so you can tweak and see the effect. A slider would be more intuitive i think.

ihf

@jonB The reason I had thought to measure scale independent of the area to be traced was that I thought it would be best to set scale using the longest known measurement on the plan and that might not be on the perimeter.

ihf

@jonb I am interested in modifying the script you were kind enough to write but I fear that my knowledge of the UI module (and perhaps Python more generally) is somewhat limited. I am trying to go through the script line by line and I have a few questions. Lines 27-28 and 36 seem to be setting a text label which never appears when the script is executed. Am I missing something? The script is already useful but it would benefit greatly by the features you mentioned (e.g., magnifying zoom effect when dragging, ability to grab and move existing points, slider for scale, pan/zoom) as well as a way to select the jpg of the floor plan (I can probably figure that one out :-). Any help you can provide is most appreciated.

JonB

i will make some comments on your github so we don't clutter the forums

ihf

@JonB I added floorplanarea-4 to the git repository with a file picker to select an image from the photo gallery and a slider for the scale setting. I tried to get the code to work in the RoomAreaView function but resorted to using a temporary file and calling the script with that file. In using the script, I also realize that a slider is fine except that the initial setting of the scale must be done with a known distance (e.g., a room width) but that measurement may not be part of the area calculation (e.g., it may be an interior room). So, a better way to set scale might be to do that explicitly (tap a button, select 2 pts with a known distance and enter that measurement in feet/inches) and then go on to mark the area to be computed.

I will say that this is already a useful script as I can now simply save a floor plan to the photo gallery and open it with the script and measure areas. Thank you for your expert assistance.

JonB

I have been playing around with getting gestures to work properly, to zoom/pan. It sort of works, but does not work inside a panel... yet. I will take a look at what you've got and incorporate into it.

A useful addition would probably be the ability to take a photo, then apply a perspective transform. for another project i was playing around with some of the built in ios rectangle detection algorithms.

ihf

@jonb I think that another useful feature would be the ability to measure distances (as opposed to areas). In other words, a linear measurement mode would permit line segments to be drawn anywhere (just as it does now for area measurement) but without connecting them to each other. Scale setting could then be invoked by a button that uses the last linear measure together with input of the known distance. Area measurement mode would work as it does now. This is essentially how Adobe Acrobat works. AA has 3 measurement modes: distance, perimeter, area. The current script could easily show perimeter by summing the distances measured. As I try to use the slider, I realize that entering the known distance would be better because it is hard to get the slider to the precise value that is based on the known distance. It would be easier to just type in that distance.

ihf

@JonB If you can find time, could you please take a look at floorplanarea-4? The script works fine but I have found that the slider is very hard to set (it changes the moment I take my finger off it) so I think a better UI would be to have a Scale Setting mode which would permit me to select 2 points for which there is a known distance and to enter the distance in feet and inches. This would also get around the problem I sometimes have where I have had to add a multiplier to the values provided by the slider because I wanted the displayed distance to be larger than the slider allowed.

The basic use case for this script is that I start with a picture of a floorplan which has some lengths shown and I want to determine the area of the space. I added a few lines at the end to permit me to select (using the image picker) an image in the photo gallery. I could not figure out how to feed the picked image to RoomAreaView directly so I used a temp file. I'm sure there must be a better way, but this works. It would also be nice if there were a way to snap the line segments to horizontal and vertical since most (though not all walls are that way). Being able to zoom for small plan images would be nice but I have managed without it.

Thanks very much for your help.

JonB

I might have forgotton to mention that I added two finger pan/zoom to the version in my repo a while back. Also, old points can be edited by grabbing the handles. This does let you be very precise... I sort of stopped working on this because I realized it probably needs a revamp from the ground up, the way I connected the touch handling with the other ui elements is pretty flawed -- it works, but is not clean, everything depends on everything else.

I will take a look at what you've got.

ihf

@JonB Wow, I somehow missed that you had done that. I will try it out. With Pan/Zoom done, the most needed feature would be the ability to set scale independent of the area measurement by selecting a known length and entering it as feet/inches.

ihf

@JonB I tried running RoomAreaFinder.py (using Pythonista 3 with the interpreter set to 2.7) with no success. It opens the console and another tab but nothing else appears.

cvp

I've installed it and I run it in Pythonista 3 without setting Python 2, but I've had to install swizzle.py, and no problem, all is ok.
Of course you need to install the jpg and Gestures.py

ihf

I will try that although I realize that now that I have switched to Pythonista 3 (v2 crashes on opening) I lost my copy of Stash (which I will use to get swizzle.py). Can you tell me the one liner for getting Stash (I tried import requests as r; exec(r.get('http://j.mp/gsp35').text) but that led to more errors. Is there a different install for Python 2.7 vs 3.5?

ihf

So, I tried to simply get Swizzle.py by putting it on my Dropbox account and using Dropbox file Picker.py (which worked earlier today) but now I find that when I run the picker, I get a tiny file picker window ??

ihf

Found I had a Dropbox File Picker.py and a Dropbox picker.py, with the latter working correctly. So now I have the 4 files, RoomAreaFinder.py, swizzle.py, Gestures.py, and the jpg and I still get no output except when I do a zoom gesture and then I get console debug output.

ihf

@jonb I would really appreciate if you could have a look at the problem I am having running your version with zoom/pan. The console is showing the debug but there is no jpg display. I would love to get this working especially with a scale setting ability as per my earlier comments. This script is really very useful.

JonB

@ihf I did make a slight update to my repo to make sure I included the right swizzle.py. Try that one.

are you running on ipad or iphone?.

ihf

I'm using an iPad 3. After deleting old versions of files that may have been causing the problem, your current git is working again. For some reason it seems easier to move points when it is not zoomed but that is a minor issue. Now I just need a way to enter a known distance that may not be part of the area calculation ( e.g. an internal room dimension). What I do now, which is somewhat clumsy, is pick 2 points with a known distance and change the scaling factor from the default of .08 until the distance shown matches the known. Then I have to restart the program (since the points used to determine the scale may not be part of the area), set the scale to the previously determined value and measure the area.

ihf

@JonB I added the (primitive) file picker snippet to your script to enable selecting an image from the photo gallery. The modified version is in my git as floorplanarea-2.py. I wish I could say I understood your code well enough to make more than trivial changes (e.g. scale setting mode with feet/inches, a way to save the image with the area calculation, etc.) but I sincerely appreciate the work you have already done.

JonB

Been busy, but I may try to pick this up again soon.

ihf

@JonB That would be great. In the meantime, I shall try to gain a better understanding of the script.

ihf

@JonB After not using the script for awhile I recently tried it and it is failing. When I run floorplanarea-6.py https://github.com/ifuchs/RoomAreaFinder/blob/master/floorplanarea-6.py, the file picker comes up, I select an image, the script just ends. If I try to run it again, I get a Value Error, "View is already being presented or animation is in progress".
Also is there a better way to use the selected image than the kluge I added which picks the image and saves to a temp file before calling the main routine (Room AreaView)?

ihf

Strange behavior. I went back to try the app again and it worked ONCE. It has reverted to the behavior described a couple of days ago. It returns immediately after selecting a photo and then if I run it again, it gives a Value error (as if the animation is running already)

ihf

@JonB Any chance you could take a look at this? Thanks.

ihf

Is this failing due to a Pythonista bug? It was working on previous releases.
```

coding: utf-8

!python2

coding: utf-8

import ui
import photos

class RoomAreaView(ui.View):
''' top level container, consisting of an imageview and an overlay.
ideally this might also contain a menu bar, for changing the mode - for instance you might have a button for enabling room drawing, another one for editing points, another for zoom/pan'''

def __init__(self, file):
    # create image view that fills this top level view.
    # since this RoomAreaView is the one that gets presented, it will be
    # resized automatically, so we want the imageview to stay tied to the
    # full view size, so we use flex.  Also, the content mode is important
    # to prevent the image from being squished
    iv = ui.ImageView(frame=self.bounds)
    iv.flex = 'wh'
    iv.content_mode = ui.CONTENT_SCALE_ASPECT_FIT
    self.add_subview(iv)
    # right now, read in file from constructor.  a future improvement would
    # be to have a file menu to select an image, which sets the iv.image
    iv.image = ui.Image.named(file)
    iv.touch_enabled = False
    # add the overlay. this is the touch sensitive 'drawing' layer, and
    # store a refernce to it.  this is set to the same size as the
    # imageview
    rv = RoomAreaOverlay(frame=self.bounds, flex='wh')
    self.add_subview(rv)
    self.rv = rv

def will_close(self):
    '''upon close, dump out the current area.  do this by first getting the set of points.  The zip notation lets us convert from a tuple of the form ((x0,y0),(x1,y1),...) to x=(x0,x1,...) and y=(y0,y1,...)'''
    x, y = zip(*self.rv.pts)
    print polygonArea(x, y, float(self.rv.scale.value)), self.rv.scale.value / 10

class RoomAreaOverlay(ui.View):
'''A touch sensitive overlay. Touches add to a list of points, which are then used to compute area. Lengths are shown for each line segment, and a scaling parameter is used to adjust the length of drawn lines to known dimensions'''

def __init__(self, *args, **kwargs):
    # call View.__init__ so we can handle any standard view constructor
    # arguments, such as frame, bg_color, etc
    ui.View.__init__(self, *args, **kwargs)
    self.touch_enabled = True
    # store list of points, and also current point for use in dragging
    self.pts = []
    self.curridx = -1
    # create a textfield to set scale.  could be a slider instead
    # scale is in units of feet/pixel, or really measurementunits/pixel
    # it might be easier to have user enter this as 1/scale (pixel/measunit), so that it will be a number >1.
    # If using a Slider instead, use self.scale.value instead of
    # float(self.scale.text) elsewhere
    self.scale = ui.Slider(frame=(400, 0, 500, 30))
    self.scale.action = self.set_scale
    self.add_subview(self.scale)
#   self.scale.text=self.scale.value
    # create a label showing current computer room area
    self.lbl = ui.Label(frame=(200, 0, 130, 30))
    self.lbl.text = 'Area'
    self.add_subview(self.lbl)
    self.lbl.bg_color = 'white'

def set_scale(self, sender):
    '''action for self.scale. called whenever scale is changed.  when that happens we update the computation of room area, and also call set_needs_display, which forces a redraw, thus redrawing distance units'''
    self.update_area()
    self.set_needs_display()

def update_area(self):
    '''update the area label by computing the polygon area with current scale value'''
    x, y = zip(*self.pts)
    area = polygonArea(x, y, self.scale.value / 10)
    self.lbl.text = 'Area: {} squnits'.format(area)

def touch_began(self, touch):
    '''when starting a touch, fiest check if there are any points very near by.  if so, set currpt to that to allow dragging previous points,
    if not, add a new point
    '''
    self.curridx = -1
    currpt = (touch.location.x, touch.location.y)
    # search existing points for a near match
    for i, p in enumerate(self.pts):
        if abs(ui.Point(*p) - ui.Point(*currpt)) < 20:
            self.curridx = i
    # if not match found, add a new point
    if self.curridx == -1:
        self.pts.append(currpt)
    self.set_needs_display()

def touch_moved(self, touch):
    ''' update the current point, and redraw'''
    self.pts[self.curridx] = (touch.location.x, touch.location.y)
    self.set_needs_display()

def touch_ended(self, touch):
    ''' called when lifting finger.  append the final point to the permanent list of pts, then clear the current point, and redraw'''
    self.curridx = -1
    self.set_needs_display()
    self.update_area()

def draw(self):
    ''' called by iOS whenever set_needs_display is called, or whenever os decides it is needed, for instance view rotates'''
    # set color to red
    ui.set_color((1, 0, 0))
    # create a copy of self.pts, and append the current point
    drawpts = self.pts

    if drawpts:
        # move path to first point:
        pth = ui.Path()
        pth.move_to(*drawpts[0])
        p0 = drawpts[0]
        for p in drawpts[1:]:
            # for each point after the first, draw a line from the previous point, compute length vector L
            # draw the line segment
            pth.line_to(*p)
            # compute point which is halfway along line between the
            # start/end point.  L is the vector pointing from start to
            # finish.  H is the Point at the halfway, referenced back to
            # global origin
            L = (ui.Point(*p) - ui.Point(*p0))
            P0 = ui.Point(*p0)
            H = P0 + L / 2  # halfway point
            # put text at the halfway point, containing length ofmsegment *
            # scale
            ui.draw_string('%3.2f' % abs(
                L * self.scale.value / 10), (H.x, H.y, 0, 0), color='red')
            # set starting point for next line segment
            p0 = p
        pth.stroke()  # draw the path
        if len(drawpts) > 2:  # 'close' the path to show area computed
            with ui.GState():
                pth = ui.Path()
                pth.move_to(*drawpts[-1])
                pth.line_to(*drawpts[0])
                pth.set_line_dash([2, 3])
                ui.set_color((1, .5, .5, .5))
                pth.stroke()
        # create a 10 pixel circle at last entered point
        ui.Path.oval(drawpts[-1][0] - 5, drawpts[-1][1] - 5, 10, 10).fill()
        # show circles for previously entered points. smaller and lighter
        ui.set_color((1, .5, .5))
        for p in drawpts[0:-1]:
            ui.Path.oval(p[0] - 3, p[1] - 3, 6, 6).fill()

def polygonArea(X, Y, scale):
'''compute scaled area of polygon,assuming it is closed '''
area = 0
j = len(X) - 1
for i in range(len(X)):
area = area + (X[j] + X[i]) * (Y[j] - Y[i]) * scale**2
j = i
return abs(area / 2)

photos.pick_image().save("temp.jpg")
v = RoomAreaView('temp.jpg')
v.present('fullscreen')```

JonB

What is the error you are getting? PAste the full traceback.
I am getting a IOError: cannot write mode P as JPEG, which im looking at...

JonB

Try this:

p=photos.pick_image()
p.save("temp.jpg")
#we need to allow some time for animation to completely complete
import time
time.sleep(1)
v = RoomAreaView('temp.jpg')
v.present() 

I cant really explain why, but it seems that trying to present a view immediately after pick_image() doesnt quite allow the animation to complete, at least sometimes. Adding a little time seems to work. 1 second is probably overkill,myou can experiment with it.

ihf

The first time I execute this script after Pythonista is started, the file picker comes up, I select an image, the script ends ( i.e. The run triangle returns) and no window is opened. If I run it again, I get:

Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/B86CEE4E-E4A9-4BB4-9CA7-6E13BDA2C2A4/Pythonista3/Documents/floorplanarea-6.py", line 160, in
v.present('fullscreen')
ValueError: View is already being presented or animation is in progress

At this point Pythonista needs to be quit or any app that tries to present a view will fail similarly.

JonB

Did you try my delay approach? You will need to force quit pythonista, then make the above mod.

ihf

Just tried it and it worked! Is there a better way to do the image selecting that does not involve saving the temp file at all?

Unrelated question: this script is extremely useful and would be much easier to use if I could select 2 points that define one known dimension and set the scale by entering it as feet and inches rather than using a slider. What I do now is select 2 points and move the slider until it is as close as I can get to the printed dimension but I can never get it quite right as the slider always changes as I take my finger off and the delta for a small movement is enough to make the positioning tricky.
Thanks so much for your expert help.

JonB

I am (slowly) working on an update that will have a much nicer user interface, allow pinch zooming for precision point placement, and have support for multiple rooms, saving and reloading results, and presenting summaries etc.

But things go slowly...

ihf

That's great! I understand and I shall be patient. Would it help in designing the UI if I posted links to 1 or 2 typical floor plans to give a better idea of what I'm trying to do?

ihf

@jonb I would be happy to discuss use cases here or, if you prefer, outside the forum. One thing you did not mention is the ability to set scale, start entering points and then clear points/lines without reentering scale. Also,, while it does not affect the area calculation very much, it would be nice to have the option to force a line segment to be vertical or horizontal as most floorplans are oriented in this way and positioning the line is a bit tricky. Having the ability to store the plan with the scale and area would be VERY helpful.I am convinced that with the additions you mention, this could be successfully sold on the App Store.

JonB

I pushed a change which includes the ability to two finger pinch zoom, and two finger pan.
I made this change a long time ago, but i now added in your file picker. Points can be moved by dragging on an existing point, thus you can set your scale, and then move points, or if you dont get it quite exact, you can zoom in and tweak.

I updated the scale textbox to allow simple math. For instance, if scal is currently 0.08, you draw a line which says 23.2, but the real distance is 25 you could enter 0.08*25/23.2, and the scale will automatically be set so your length is exact.

I also added a clear button to clear the path.

https://github.com/jsbain/RoomAreaFinder.git

anyway, just sort of temporary changes using the old ui.

ihf

@jonb Here is a "real world" image of a floor plan that I am trying to measure. If I zoom in, the red circle is sometimes too large to position accurately. Also, would be nice to be able to measure the total area as well as the area of internal rooms or spaces. Right now I can do either but not both on one plan. Also, might be better if the window were full screen?