Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Doc Block
Apr 15, 2003
Fun Shoe
Can the analysis part be done on smaller images? You could set it all up to use OpenGL for drawing your live video feed a la most camera apps (look up GPUImage), and have OpenGL render to a small framebuffer, then grab that and do your analysis. Depending on what kind of analysis you're doing, you could even draw to the small framebuffer with a shader that does some preprocessing for you.

edit: I'm assuming you aren't converting every frame to a UIImage. You aren't, right?

Adbot
ADBOT LOVES YOU

tarepanda
Mar 26, 2011

Living the Dream
I am converting every frame to a UIImage for display in a UIImageView, actually, as shown here: http://www.devsrealm.com/objective-c/direct-access-to-the-camera/

The actual processing also requries UIImages, so I'd have to do it anyway. And yeah, I resize them to a much smaller resolution before processing.

There's next to no drawing on the video feed, so that's not an issue. It's a CV thing.

Doc Block
Apr 15, 2003
Fun Shoe
Putting every frame in a UIImageView has got to be really inefficient. Maybe not, but I would think that'd be really slow.

My suggestion would be to use OpenGL for drawing your live video preview. Take a look at GPUImage, which can set it all up for you. They've got a sample app that uses GPUImage to do real-time color tracking, and it even has a motion detector filter.

If you don't want to use OpenGL for drawing your video feed, and you don't need the live preview to be altered first, AVFoundation has a special Core Animation layer to draw the live video preview:
Objective-C code:
#import <QuartzCore/QuartzCore.h>	// requires QuartzCore framework
...
AVCapturePreviewVideoLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession];
// videoView is just an ordinary UIView
previewLayer.frame = self.videoView.bounds;
previewLayer.videoGravity = AVLayerVideoGravityAspectFill;    // or whatever you want
[self.videoView.layer addSublayer:previewLayer];

Doc Block fucked around with this message at 06:05 on Sep 11, 2012

tarepanda
Mar 26, 2011

Living the Dream
I don't think it would end up making a difference either way since I'd still have to convert every single frame to a UIImage for analysis as it is... but thanks.

Edit: And honestly, the analysis is perfectly fine as it is -- there's no lag until I try to change preset modes to take a picture. If I use 640 x 480 and never change the preset mode, there's no lag at all. The problem is that it's just a lovely picture.

tarepanda fucked around with this message at 06:25 on Sep 11, 2012

EatDirt
Nov 13, 2009
Thanks for all the advice. Kind of confusing with the conflicting opinions but I think I have a clear idea what to do. I'll be back requesting help when I get stuck I am sure. :wink:

stray
Jun 28, 2005

"It's a jet pack, Michael. What could possibly go wrong?"
Jesus Christ, why is date-and-time programming so complicated!

My library branch directory app is coming along nicely, but I want to display the branch's schedule today. Let's say a branch has the following schedule:
Sun 1:00 p.m. — 5:00 p.m.
Mon 9:00 a.m. — 9:00 p.m.
Tue 9:00 a.m. — 9:00 p.m.
Wed 9:00 a.m. — 9:00 p.m.
Thu 9:00 a.m. — 9:00 p.m.
Fri 9:00 a.m. — 5:00 p.m.
Sat 9:00 a.m. — 5:00 p.m.


Rather than put in the whole schedule – which will take up a lot of room in the UI – I'd like to have a button which displays the branch's schedule for today only. (Then, if they tap on the button, it will load a new view with the branch's full schedule.)

But holy smokes, does Cocoa ever make this complicated! There seem to be lots of parts involved here: NSDate, NSDateComponents, NSCalendar... I don't get ANY of this! Does anyone know how to do this or of a decent tutorial?

tarepanda
Mar 26, 2011

Living the Dream
The most confounding thing about all that bullshit is that NSDate objects are immutable. I kind of got mad and made my own date class with the functionality I needed...

Edit: I have a UIButton that I made in the storyboard and am adding a title to later, in code; the changes don't show up until I touch the UIButton, for some reason. What's the deal with that?

tarepanda fucked around with this message at 06:07 on Sep 12, 2012

Echo Video
Jan 17, 2004

stray posted:

But holy smokes, does Cocoa ever make this complicated! There seem to be lots of parts involved here: NSDate, NSDateComponents, NSCalendar... I don't get ANY of this! Does anyone know how to do this or of a decent tutorial?

Try this as a starting point:

code:
NSArray *openTimes = [NSArray arrayWithObjects:
	@"Sun 1:00 p.m. — 5:00 p.m.", 
	@"Mon 9:00 a.m. — 9:00 p.m.", 
	@"Tue 9:00 a.m. — 9:00 p.m.",
	@"Wed 9:00 a.m. — 9:00 p.m.", 
	@"Thu 9:00 a.m. — 9:00 p.m.",
	@"Fri 9:00 a.m. — 5:00 p.m.", 
	@"Sat 9:00 a.m. — 5:00 p.m.", nil];
NSUInteger dayOfWeek = [[NSCalendar currentCalendar] ordinalityOfUnit:NSDayCalendarUnit inUnit:NSWeekCalendarUnit forDate:[NSDate date]];
openTimeLabel.text = [openTimes objectAtIndex:(dayOfWeek - 1)];
e:

tarepanda posted:

Edit: I have a UIButton that I made in the storyboard and am adding a title to later, in code; the changes don't show up until I touch the UIButton, for some reason. What's the deal with that?

Check the state config setting on the inspector, you might have Highlighted selected instead of Default.

Echo Video fucked around with this message at 06:21 on Sep 12, 2012

tarepanda
Mar 26, 2011

Living the Dream

Echo Video posted:

Check the state config setting on the inspector, you might have Highlighted selected instead of Default.

Good call. That was exactly it.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



tarepanda posted:

The most confounding thing about all that bullshit is that NSDate objects are immutable. I kind of got mad and made my own date class with the functionality I needed...

I'm curious, what were you trying to do?

Toady
Jan 12, 2009

tarepanda posted:

The most confounding thing about all that bullshit is that NSDate objects are immutable. I kind of got mad and made my own date class with the functionality I needed...

If I recall correctly, NSDate objects are just wrappers around a Unix timestamp.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Different epoch: midnight January 1, 2001.

Doctor w-rw-rw-
Jun 24, 2008

tarepanda posted:

The most confounding thing about all that bullshit is that NSDate objects are immutable. I kind of got mad and made my own date class with the functionality I needed...

Edit: I have a UIButton that I made in the storyboard and am adding a title to later, in code; the changes don't show up until I touch the UIButton, for some reason. What's the deal with that?

Dates are complicated as poo poo and NSDate is a fairly heavy wrapper around a LOT of engineering to make it work across a lot of different locales. Being immutable is The Right Thing™. Writing your own date class yourself (that isn't a wrapper around well-established library) is in most cases a retarded thing to do without special requirements that warrant it.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer
FYI: This took me way too long to figure out, but apparently the the way to get an existing app to start doing 4" layouts is to define a 4"-sized default image in the project file. Did I miss some documentation on this?

AlwaysWetID34
Mar 8, 2003
*shrug*
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

AlwaysWetID34 fucked around with this message at 17:50 on Jan 18, 2019

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

McFunkerson posted:

If so I missed it too, I looked all over the iOS/Xcode 4.5 release notes before jumping on the Developer Forums and finding the answer.

This is why I liked WWDC hardware releases. I feel like features that needed developer intervention, like @2x-stuff, got explained a lot more efficiently when a critical mass of developers/bloggers had the chance to pick an Apple engineer's brain about it. It's especially weird, given that there's probably going to be a lot of leterboxed apps out there when the iPhone 5 comes out.

Toady
Jan 12, 2009

Doctor w-rw-rw- posted:

Dates are complicated as poo poo and NSDate is a fairly heavy wrapper around a LOT of engineering to make it work across a lot of different locales.

I could have sworn one of the WWDC presentations stated that NSDate is nothing more than a boxed timestamp.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Toady posted:

I could have sworn one of the WWDC presentations stated that NSDate is nothing more than a boxed timestamp.
What else would it need to store? The complex part is the code to do anything interesting with that timestamp, not the data structure.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Looking at a class-dump of CoreFoundation, NSDate is actually a class cluster with two concrete subclasses (plus a placeholder subclass for alloc-ing):

__NSDate which has a double ivar called _time, presumably seconds since some epoch.
__NSTaggedDate which doesn't have any ivars and is probably using the tagged pointers trick as mentioned on Mike Ash's blog recently.

But yeah, keeping a date itself isn't so hard, it's doing any sort of arithmetic with it that gets hairy very quickly, which is why there's a glut of helper methods for that stuff.

There's also the CFDate stuff of course.

E: Weird that it's a double though, using a floating point to keep time seems risky.

Carthag Tuek fucked around with this message at 04:41 on Sep 13, 2012

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
It probably gives you like sub-microsecond accuracy across ten thousand years in either direction (numbers pulled out of my rear end), and it'll be way faster for any arithmetic, so it seems like a reasonable choice given those trade offs.

Toady
Jan 12, 2009

Plorkyeran posted:

What else would it need to store? The complex part is the code to do anything interesting with that timestamp, not the data structure.

The point wasn't the data structure. I'm saying NSDate does very little other than represent a timestamp and that the complicated functionality is in other classes.

Toady fucked around with this message at 08:02 on Sep 13, 2012

Small White Dragon
Nov 23, 2007

No relation.

ultramiraculous posted:

FYI: This took me way too long to figure out, but apparently the the way to get an existing app to start doing 4" layouts is to define a 4"-sized default image in the project file. Did I miss some documentation on this?
Is there a set naming convention for this, ala @2x files?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



pokeyman posted:

It probably gives you like sub-microsecond accuracy across ten thousand years in either direction (numbers pulled out of my rear end), and it'll be way faster for any arithmetic, so it seems like a reasonable choice given those trade offs.

Yeah that's pretty much it, on further investigation:

typedef double NSTimeInterval;

NSTimeInterval is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.

lord funk
Feb 16, 2004

McFunkerson posted:

If so I missed it too, I looked all over the iOS/Xcode 4.5 release notes before jumping on the Developer Forums and finding the answer.

What's the answer?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



I have this bit in my code, but it just seems like a lot of work for something that might be easier to do another way.

Objective-C code:
NSArray *someArray = @[ @"a", @"b", @"cSpecial" ];
__block id specialObj = nil;

// The special object is usually the last one, but that can't be guaranteed. There will only be one.
[someArray enumerateObjectsWithOptions:(NSEnumerationReverse) usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    if ([obj hasSuffix:@"Special"]) { //The test is more complex than isEqual:.
        specialObj = obj;
        *stop = YES;
    }
}];

NSMutableArray *someArrayWithoutSpecialObj = [someArray mutableCopy];

[someArrayWithoutSpecialObj removeObject:specialObj];

//move on, do one thing with someArrayWithoutSpecialObj and another with specialObj...
I would prefer instead something like:

Objective-C code:
NSArray *someArray = @[ @"a", @"b", @"cSpecial" ];
NSMutableArray *someArrayWithoutSpecialObj = [someArray mutableCopy];
id specialObj = [someArrayWithoutSpecialObj removeAndReturnObjectFulfillingTest:^(BOOL)(id obj, NSUInteger idx) {
    return [obj hasSuffix:@"Special"]
}];

//move on, do one thing with someArrayWithoutSpecialObj and another with specialObj...
Anyone doing a similar thing with a good tip? I guess I could put it in a category but ugh...

Kallikrates
Jul 7, 2002
Pro Lurker
filteredArrayUsingPredicate:

and the predicate would be something like:

@"contains %@", @"Special"

But that would be more general assuming @"Special" can only be a suffix.
you could also try a regex match in the predicate

@"matches %@", @"regex"

lord funk
Feb 16, 2004

Is there a clever way to force -viewDidUnload to simulate performance with low memory conditions? I'm only getting the unloaded view action about 15% of the time when I test for it, and I'd rather just trigger it and see what happens.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Kallikrates posted:

filteredArrayUsingPredicate:

and the predicate would be something like:

@"contains %@", @"Special"

But that would be more general assuming @"Special" can only be a suffix.
you could also try a regex match in the predicate

@"matches %@", @"regex"

I want both the matching object and the filtered array, and most ways I can think of eventually end up doing double work, searching through the array twice.

Kallikrates
Jul 7, 2002
Pro Lurker

Carthag posted:

I want both the matching object and the filtered array, and most ways I can think of eventually end up doing double work, searching through the array twice.

You could use one of the IndexOfMethods which would return an index you could use to directly access the object late.
Better than using removeObject which will just search twice.
so get the index, get a references of the object using the index, then delete it using the index

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Kallikrates posted:

You could use one of the IndexOfMethods which would return an index you could use to directly access the object late.
Better than using removeObject which will just search twice.
so get the index, get a references of the object using the index, then delete it using the index

Yeah after posting I saved the index in my block and use removeObjectAtIndex: instead, but it still seems kinda gross. I guess what I'd actually like is some sort of popObjectAtIndex: method that would let me get the object out in the same operation as removing it from the array.

dizzywhip
Dec 23, 2005

Carthag posted:

Anyone doing a similar thing with a good tip? I guess I could put it in a category but ugh...

I don't think there's a significantly simpler way to do this. This is the best I can come up with, which is only slightly better. I don't really think it's that bad though.

Objective-C code:
NSArray* someArray = ...;

NSUInteger index = [someArray indexOfObjectPassingTest: ^(BOOL)(id object, NSUInteger index, BOOL* stop) {
    return [object hasSuffix: @"Special"];
}];

id object                     = someArray[index];
NSMutableArray* filteredArray = [someArray mutableCopy];
[filteredArray removeObjectAtIndex: index];

haveblue
Aug 15, 2005



Toilet Rascal
Has anyone tried to use the turn based match system in Game Center? I'm trying to think of a general strategy for building a game around it without requiring the use of multiple devices or GC accounts. There doesn't seem to be any way to start a 1-player turn based match, so my idea right now is simply to firewall off the game code from the matchmaking service and write my own harness for it, but this seems like far too much effort for something the API designer should have anticipated. Am I missing something?

kitten smoothie
Dec 29, 2001

Will iOS6 based iPads show the 4" optimized UI on iPhone-only apps, assuming they've got a 4" UI?

Want to get started on a UI revamp for an app of mine and get some real-hardware testing done on it this week before my iPhone 5 turns up.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

lord funk posted:

Is there a clever way to force -viewDidUnload to simulate performance with low memory conditions? I'm only getting the unloaded view action about 15% of the time when I test for it, and I'd rather just trigger it and see what happens.

I seem to remember -viewDidUnload becoming or essentially already being a no-op, partly because nobody used it properly and partly because it didn't solve any of the problems it was meant to.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Carthag posted:

Yeah after posting I saved the index in my block and use removeObjectAtIndex: instead, but it still seems kinda gross. I guess what I'd actually like is some sort of popObjectAtIndex: method that would let me get the object out in the same operation as removing it from the array.

Is there anything stopping you from putting that in a category on NSArray?

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

pokeyman posted:

I seem to remember -viewDidUnload becoming or essentially already being a no-op, partly because nobody used it properly and partly because it didn't solve any of the problems it was meant to.

Yeah, as of iOS6 it's not going to get called anymore.

Apparently the strategy of throwing away the *entire* view when a memory warning sweep came through wasn't really necessary. Basically as of iOS6, the OS will only throw away the backing layer bitmap for the view, rather than trashing the entire view hierarchy. That realization + realizing so many crashes happened after viewWillUnload got called prompted the change.


To answer lord funk's question, you could add a button to do something like this:

http://stackoverflow.com/questions/2784892/simulate-memory-warnings-from-the-code-possible

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



pokeyman posted:

Is there anything stopping you from putting that in a category on NSArray?

I'm only doing it in one place, it just seemed like a thing that an NSArray would be able to do. Doesn't matter that much, I was just sperging a bit.

I'm having an actual problem with mktime(), but ONLY when in running the app; the code works fine in my test case. I'm probably really dumb, but what am I doing wrong here?

C code:
(lldb) po dateString
(NSString *) $0 = 0x000000010bb4d270 2 May 2009 20:07:12

//it's parsed via strptime() into a tm struct called timeResult alright:

(lldb) p timeResult
(tm) $1 = {
  (int) tm_sec = 12
  (int) tm_min = 7
  (int) tm_hour = 20
  (int) tm_mday = 2
  (int) tm_mon = 4
  (int) tm_year = 109
  (int) tm_wday = 242064
  (int) tm_yday = 1
  (int) tm_isdst = 1
  (long) tm_gmtoff = 4491349904
  (char *) tm_zone = 0x0000000000000000
}

// but when I run mktime to get seconds since epoch to put into NSDate, it breaks:

(lldb) p (time_t)mktime(&timeResult)
(time_t) $2 = -1
Why is my timeResult struct resulting in negative one? It works in my test case with the exact same string...

NB: I'm using strptime()/mktime() because NSDateFormatter is too slow when handling thousands of dates while opening a file.

Edit: I guess it must have to do with tm_gmtoff being wildly inappropiate, something about the locale or environment is apparently different when running a test case and the app itself.

Edit 2: Jesus christ, I went and checked Date & Time in System Preferences and I had Bangui, Central African Republic as my timezone (incidentally it's the same as ECT, but I guess its locale is hosed up). Setting my timezone to my actual country fixed it.

Carthag Tuek fucked around with this message at 00:09 on Sep 15, 2012

tarepanda
Mar 26, 2011

Living the Dream
Is there a good site with a list of all of the changes from iOS 5 to 6 and what they mean rather than a simple itemized list or "you can do more picture fun times" articles? Videos are a no-go for me since I'm mostly deaf.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



The WWDC videos used to have subtitles, but I can't get it to work with the 2012 ones. The 2010 ones work fine from a quick test. I'm probably too tired to gently caress around with serious stuff any more today.

You can see itemized API diffs in XCode help under iOS 6 Library > General > iOS x.y Diffs.

Adbot
ADBOT LOVES YOU

Small White Dragon
Nov 23, 2007

No relation.

lord funk posted:

Is there a clever way to force -viewDidUnload to simulate performance with low memory conditions? I'm only getting the unloaded view action about 15% of the time when I test for it, and I'd rather just trigger it and see what happens.
The simulator does have a menu option to simulate low memory condition actions.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply