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
the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





Is there a cross platform way to get the rgb value of a specific pixel displayed on screen?

The pixel may not be constrained to a certain window, unfortunately. I also need a solution that doesn't rely on dumping screenshots. Language doesn't really matter, but C or Python would be ideal. I also don't really care about OSX, but it would be nice if it worked there too.

Adbot
ADBOT LOVES YOU

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

the talent deficit posted:

Is there a cross platform way to get the rgb value of a specific pixel displayed on screen?

The pixel may not be constrained to a certain window, unfortunately. I also need a solution that doesn't rely on dumping screenshots. Language doesn't really matter, but C or Python would be ideal. I also don't really care about OSX, but it would be nice if it worked there too.

PyQt (or use the C++ version directly if you have problems with the Python wrapper). Works on Qt, Mac and Linux. I'm not sure what you mean by "dumping screenshots", but I assume you mean you can't save it to an image on disk and then look at the image. The following code will grab the entire screen into a QPixmap in memory and then you get the individual pixel value:

code:
QPixmap::grabWindow(QApplication::desktop().winId()).toImage().pixel(x, y);

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





JoeNotCharles posted:

PyQt (or use the C++ version directly if you have problems with the Python wrapper). Works on Qt, Mac and Linux. I'm not sure what you mean by "dumping screenshots", but I assume you mean you can't save it to an image on disk and then look at the image. The following code will grab the entire screen into a QPixmap in memory and then you get the individual pixel value:

code:
QPixmap::grabWindow(QApplication::desktop().winId()).toImage().pixel(x, y);

This is fantastic, thankyou!

Jo
Jan 24, 2005

:allears:
Soiled Meat
I have a set A that contains elements {a, b, e, ff, sf, cd, flol}.

I have also the sets

B{erf, fds, grh, thj, jju, kkoo, poi, iilh, hjm}
C{blah blah blah}
D{blah blah blah}

and so forth.

I need to find which of the other sets contains the largest number of matching elements from A. The elements are not ordered (rather, cannot be ordered because order is meaningless).

Is there a name for this kind of problem? I'm really at a loss for anything other than exhaustive search. :gonk:

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Jo posted:

Is there a name for this kind of problem? I'm really at a loss for anything other than exhaustive search. :gonk:

I'd call it a "maximal intersection" problem.

Jo posted:

The elements are not ordered (rather, cannot be ordered because order is meaningless).

You can always impose an ordering on a set (n.b. please do not bring up the axiom of choice). Unless O(n log k) (k being the size of the largest set) is too much, I'd just do the standard sort-intersection, except of course you don't actually need to materialize the intersections.

EDIT: I left the algorithm deliberately vague just in case this is a homework assignment. If you need that clarified, I'd be happy to.

rjmccall fucked around with this message at 06:33 on Oct 12, 2008

Jo
Jan 24, 2005

:allears:
Soiled Meat

rjmccall posted:

You can always impose an ordering on a set (n.b. please do not bring up the axiom of choice). Unless O(n log k) (k being the size of the largest set) is too much, I'd just do the standard sort-intersection, except of course you don't actually need to materialize the intersections.

I was hoping to avoid sorting, as the function I have to determine if an object is in a set is featurePoint.equals( fp2 ). equals does a rough evaluation and returns true if the right number of attributes match up.

Perhaps sorting is really the only practical way, then. I'll see what I can do to impose some sortable attributes. Thank you much for your advice.

EDIT: No, this isn't a homework assignment. I know it sounds like it, but I'm dicking around with an image-search engine. The sets I've been talking about are arrays of feature points from my corner/feature detector.

Jo fucked around with this message at 07:06 on Oct 12, 2008

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Jo posted:

I was hoping to avoid sorting, as the function I have to determine if an object is in a set is featurePoint.equals( fp2 ). equals does a rough evaluation and returns true if the right number of attributes match up.

Ugh, yeah, structures with deep equality semantics are just really difficult to work with. I can't see how you can improve substantially over the brute-force algorithm without further assumptions, though.

EDIT: Oh, that sounds cool. Can you explain a little (or even just give me a pointer) about what an image feature is and what it means to evaluate it? Maybe I can help you with an ordering.

rjmccall fucked around with this message at 07:16 on Oct 12, 2008

Fitret
Mar 25, 2003

We are rolling for the King of All Cosmos!
I need some help with Regular Expressions. I have a program (Regex Importer for Meedio) that will automatically go through a directory of TV shows and apply regex to the files in order to fill in variable names so they can look up the information online and fill in the missing parts.

The only non-standard syntax you need to know to understand the regex below is (?<VariableName>REGEXPATTERN) where essentially anything that matches the REGEXPATTERN will get tossed into the variable. So for example, if you had the following string:

"Hello5" and the following regex:
(?<Message>[a-zA-Z]*)[0-9]

You would end up with the variable Message containing the string "Hello"

That having been said, here's my regex:

(.*\\)?(?<SeriesName>.*?)(\.|\s)([sS](?<SeasonNumber>[0-9][0-9]?)[^0-9]?[eE](?<EpisodeNumber>[0-9]{2})|(?<SeasonNumber>[0-9][0-9]?)[^0-9]?(?<EpisodeNumber>[0-9]{2}))[^a-zA-Z](\s-\s(?<EpisodeName>)[^\.]*|.*)\.(?<FileType>...)

The files I'm trying to match follow the patterns below:

Battlestar Galactica Season 3\Battlestar Galactica S03E01 - Occupation.mkv
Entourage.501.720p.mkv
Entourage.S05E03.720p.09212008.mkv

However, for BSG I get no EpisodeName, which makes sense because it's matching the easier .* rather than the more complex pattern that fits BSG. How can I match the BSG episode names without getting crap like "720p" or "720p.02212008" for the other episodes? It's unlikely I'll have more episodes like this, as I ripped these from my DVD collection and renamed them by hand, but since I have the episodes in that format, it'd be nice to have one piece of regex that matches everything.

Every Entourage episode comes up with a blank SeasonName, but if I rename the file to "Entourages.S05E03...", then I get "s" as the SeasonName.

Edit: I own BSG on DVD, and subscribe to HBO. I have a server with a lot of storage, so I decided to rip/record everything to that and save it because data is ridiculously cheap these days.

Fitret fucked around with this message at 19:36 on Oct 12, 2008

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
http://forums.somethingawful.com/showthread.php?threadid=2953970

Fitret
Mar 25, 2003

We are rolling for the King of All Cosmos!

I subscribe to HBO and record them with lovely applications that don't let me change the naming structure because I'm too cheap to pay for SageTV or BeyondTV. Plus, these will auto-convert them H264 .mkv's for me. That having been said, I've spent enough time trying to figure out this regex that I might just bite the bullet and buy SageTV or BeyondTV if they'll let me choose how to rename my episodes and automatically compress them. Vista's MediaCenter won't, which is lame.

Fitret fucked around with this message at 19:17 on Oct 12, 2008

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
If you told us what DVR application you're using, I bet there's someone here who knows enough about it to tell you how to set it up to use any naming structure you like. Also, I'm not sure why you edited out half of the examples in your post, it's just going to make it harder for anyone to write a working regex for what you need. There's no need to be embarrassed about the shows you watch; we're all friends here. :)

floWenoL
Oct 23, 2002

Fitret posted:

I subscribe to HBO and record them with lovely applications that don't let me change the naming structure because I'm too cheap to pay for SageTV or BeyondTV. Plus, these will auto-convert them H264 .mkv's for me. That having been said, I've spent enough time trying to figure out this regex that I might just bite the bullet and buy SageTV or BeyondTV if they'll let me choose how to rename my episodes and automatically compress them. Vista's MediaCenter won't, which is lame.

Man, I wish I had enough money to afford a dedicated DVR box with enough horsepower to do high-def recording and H264 encoding. I don't get it, though; if you're rich enough to have such a machine, why can't you just buy SageTV or BeyondTV? :)

Fitret
Mar 25, 2003

We are rolling for the King of All Cosmos!

Avenging Dentist posted:

If you told us what DVR application you're using, I bet there's someone here who knows enough about it to tell you how to set it up to use any naming structure you like. Also, I'm not sure why you edited out half of the examples in your post, it's just going to make it harder for anyone to write a working regex for what you need. There's no need to be embarrassed about the shows you watch; we're all friends here. :)

TVEngine3. It's a Meedio plug-in that doesn't work very well. Considering only 1 other goon that I know of uses Meedio, I doubt anyone here has used this software.

floWenoL posted:

Man, I wish I had enough money to afford a dedicated DVR box with enough horsepower to do high-def recording and H264 encoding. I don't get it, though; if you're rich enough to have such a machine, why can't you just buy SageTV or BeyondTV? :)

The box cost like $600. The H264 encoding is done by my personal PC, not the HTPC. I haven't bought SageTV or BeyondTV because based on what I've read about them, they're not all that great, and if they're not going to be perfect for me, I don't see any reason to buy them when Vista's Media Center is free with the OS. And before you ask why I sprang for the more expensive version instead of getting the cheaper Vista + BeyondTV or SageTV, I work for Microsoft, and Vista Ultimate was like, $50.

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe
What exactly is the .bss segement? I get that it's where it stores poo poo as the program is loading, but is it gone after that or what?

I noticed it showed up in one of my programs, but doesn't seem to actually take up any physical space. Is this right?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

slovach posted:

What exactly is the .bss segement? I get that it's where it stores poo poo as the program is loading, but is it gone after that or what?

I noticed it showed up in one of my programs, but doesn't seem to actually take up any physical space. Is this right?

It stores static data that should be initialized to zero. Because it's known to contain nothing but zeroes, it's not actually realized in the executeable file - the operating system allocates space for it in RAM and fills that space with zeroes on its own.

Sparta
Aug 14, 2003

the other white meat
In PHP I'm trying to take a url that people submit and strip it down a bit.

So people can input things like:

http://mikemanfrin.com
http://www.mikemanfrin.com
mikemanfrin.com
mikemanfrin.com/blog

And I want to make all of these change to:

mikemanfrin.com

Essentially strip all extra data off the string.

I looked at explode, but I couldn't figure out how to account for the different inputs people might have, or how to make sure what they enter is an actual url (ie if someone just typed in 'domain', it should show an error).

I'm fairly inexperienced at PHP, so I'm sorry if this is an exceptionally dumb question.

tef
May 30, 2004

-> some l-system crap ->
http://uk.php.net/function.parse-url

Also PHP Thread: http://forums.somethingawful.com/showthread.php?threadid=2802621

Jo
Jan 24, 2005

:allears:
Soiled Meat

rjmccall posted:

Ugh, yeah, structures with deep equality semantics are just really difficult to work with. I can't see how you can improve substantially over the brute-force algorithm without further assumptions, though.

EDIT: Oh, that sounds cool. Can you explain a little (or even just give me a pointer) about what an image feature is and what it means to evaluate it? Maybe I can help you with an ordering.

Feature points contain a lot of information, among the details:
Relative x and y coordinates in the image. (I.E. 10% from left, 40% from top)
A 5x5 kernel of deltas, detailing how the image changes at that feature point.
A tiny histogram (probably going to take this out) of color values.

I would sort the feature points by location, but if someone submits a tiny chunk of the image, the feature points aren't going to match up. If the end-user submits a resized photo or a slightly shifted photo, the points will match. Instead, I'm going to have to find some way to sort based on a 5x5 matrix. Again, the problem exists that this matrix might not be matching exactly to the one stored in the database. I'm kinda' stuck here.

Mormon Mother
Jan 23, 2008
Self diagnosed!
I'm currently working on a computer engineering assignment where I am required to write a small program in Turing that requests 10 integers, then outputs them in reverse order, declaring whether or not each integer is an even or an odd number.

Here is my program as of now:

code:
var numbers : array 1 .. 10 of string
var number : string

for i : 1 .. 10
    loop
        put "Please enter an integer."
        get number
        exit when strintok (number) = true
        cls
        put "ERROR: Input is not an integer.  Try again when prompted."
        delay (2000)
        cls
    end loop
    numbers (i) := number
    cls
end for
put "The integers you entered, in reverse order, are:"
for decreasing i : 10 .. 1
    put numbers (i)
    delay (500)
end for
Getting the integers and displaying them in reverse order was simple enough, but I cannot for the life of me figure out how to get Turing to determine whether or not each integer is an even or an odd number. I know I've done this before, and I know the answer should be incredibly simple, but I feel as if I've tried everything I can think of.

TagUrIt
Jan 24, 2007
Freaking Awesome
(Apologies in advance for pedanticism.)

I'm not too familiar with Turing, but it seems that it has an 'if [true|false] then statement1 else statement2" construct. With that, you can do the splitting. Now all you need is a way to find out whether the number is even ('true' or 'false').

You know that even numbers are of the form 2m, and odd numbers are of the form 2m+1. What happens in Turing if you divide an integer by another integer? For example, what does Turing think 3/2 is? I'm betting it is 1, although 2 is possible also. It is highly unlikely that it returns the "real" answer of 1.5 due to the types of the inputs (integers); we wouldn't be able to do something simple like x = (x/2)!

So, if p/2 yields a value m, then 2m should be p. (Why might they not be the same?) Well, if 3/2 gives us 1, and 1*2=2, we notice that 2 isn't equal to 3. Hmmm...

Mormon Mother
Jan 23, 2008
Self diagnosed!
I just tried 3/2, the output was 1.5. I then tried
code:
var two, three : int

two := 2
three := 3

put three / two
The output was still 1.5

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

Assberging posted:

I just tried 3/2, the output was 1.5. I then tried
code:
var two, three : int

two := 2
three := 3

put three / two
The output was still 1.5

%

Perhaps?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
It's "mod"

As in foo := bar mod 2

Also, I want you to go to school and call your teacher a stupid fag because seriously Turing is basically just a crappy version of Pascal.

Mormon Mother
Jan 23, 2008
Self diagnosed!

Avenging Dentist posted:

It's "mod"

As in foo := bar mod 2

Also, I want you to go to school and call your teacher a stupid fag because seriously Turing is basically just a crappy version of Pascal.

Got it! Thanks :)

TagUrIt
Jan 24, 2007
Freaking Awesome
Oops. Sorry about that. (Turing really does that? Wow. That's pretty dumb.)

Ru
Mar 25, 2005
oops didnt read the OP

Ru fucked around with this message at 15:03 on Oct 16, 2008

citsejam
Dec 24, 2005

<3
In C:

quote:

char c = 148;
printf("%i", c);

Rather than outputting 148, it gives me -108. On closer inspection, I seem to be getting incorrect values when an ASCII character's integer value is => 100. Is something wrong with my libraries, or am I retarded/missing something?

EDIT: Whoops, probably should've posted this in the C/C++ thread.

citsejam fucked around with this message at 02:23 on Oct 18, 2008

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

citsejam posted:

Rather than outputting 148, it gives me -108. On closer inspection, I seem to be getting incorrect values when an ASCII character's integer value is => 100. Is something wrong with my libraries, or am I retarded/missing something?

Pretty much that. :) You're outputting an unsigned value with a signed flag. Signed chars range from -128 to 127. Use %u

citsejam
Dec 24, 2005

<3

Avenging Dentist posted:

Pretty much that. :) You're outputting an unsigned value with a signed flag. Signed chars range from -128 to 127. Use %u

Using %u instead spits out 4294967188 :(.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Well first of all you should be using an unsigned char if you actually care about values >127. Also, printf casts everything up to an int (*) when you call it.


* Lies

citsejam
Dec 24, 2005

<3
Thanks. Making the characters unsigned did the trick.

Z-Bo
Jul 2, 2005
more like z-butt
Dumb question.

What is the difference between a Perl regular expression and a regular expression? I tried Googling, but the only interesting thing I found is that two regular expression matching engines can differ based upon their matching technique, backtracking or DFA (interesting but not pertinent).

Comment by Bill McCloskey on http://blog.mozilla.com/dmandelin/2008/10/06/squirrelfishing-in-regexp-dnajs/ posted:

the backtracking approach doesn’t use longest-match semantics as the NFA approach does. So the two techniques differ in more than their performance properties. Here’s an example, written in Python:
import re
re.match(’(|a)*’, ‘aaaaa’).span() # returns (0, 0)
I would expect the whole string to match, but instead only the epsilon at the beginning of the string matches. This seems really weird to me, but it’s how all backtracking-based matchers work: they pick the “left-most match” rather than the longest one.

It’s too bad that getting NFA-based matchers to do grouping is such a pain in the rear end.

What I'm looking for are examples of how a (Ruby|Java|.NET) regex might match differently in Perl, and why?

I did find ECMAScript 3 Regular Expressions are Defective by Design, but that looks like a special case.

My basic question is: is there a portable syntax for (a subset of) regexes?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Nearly every language uses Perl Compatible Regular Expressions. There isn't really a whole lot out there that just uses POSIX regexes.

KaeseEs
Feb 23, 2007

by Fragmaster
POSIX defines both basic (used by grep) and extended (used by egrep) regular expressions (you can check regex(3) for the functions and regex(7) for more info, but the web is your best bet for these). As you would guess, POSIX regexes are portable to anything nixy.

Perl-compatible regular expressions, on the other hand, are the de facto standard for modern languages, and are your best bet for cross-platform portability.


A (huge) guide to regex compatability (in terms of whether things are implemented, differences are even harder to track 'well') between languages and frameworks can be found at http://www.regular-expressions.info/refflavors.html (scroll down a little for megatable).

zootm
Aug 8, 2006

We used to be better friends.

Z-Bo posted:

What is the difference between a Perl regular expression and a regular expression? I tried Googling, but the only interesting thing I found is that two regular expression matching engines can differ based upon their matching technique, backtracking or DFA (interesting but not pertinent).
On a more theoretical level, Perl regexes can actually define more than the set of regular languages, which means "regular expression" is something of a misnomer, as well as meaning that Perl regexes cannot, in general, be expressed as DFAs.

Vanadium
Jan 8, 2005

Also the escaping rules for non-perl regexes are going to drive you mad.




:doom:

tripwire
Nov 19, 2004

        ghost flow

Vanadium posted:

Also the escaping rules for non-perl regexes are going to drive you mad.




:doom:

Oh lord yes. And the ability to capture substrings is severely limited and problematic in posix regex compared to perl compatible RE, as I learned recently.

POKEMAN SAM
Jul 8, 2004
In C can you somehow compare two FILE * to see if they are pointing at the same file? I don't care about compatibility with symlinks or whatever, these will be two FILE * pointing to potentially one regular file on the hard drive.

TSDK
Nov 24, 2003

I got a wooden uploading this one

Ugg boots posted:

In C can you somehow compare two FILE * to see if they are pointing at the same file? I don't care about compatibility with symlinks or whatever, these will be two FILE * pointing to potentially one regular file on the hard drive.
No. All you can say is whether or not they're the same file handle - you can potentially have more than one open file handle on the same file.

EDIT: vvv You can do that, but it's platform specific and non-standard.

TSDK fucked around with this message at 21:39 on Oct 24, 2008

Adbot
ADBOT LOVES YOU

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Ugg boots posted:

In C can you somehow compare two FILE * to see if they are pointing at the same file? I don't care about compatibility with symlinks or whatever, these will be two FILE * pointing to potentially one regular file on the hard drive.

Untested, but this should work. I don't know if there's a shorter way; this is just the first solution that I thought of.

code:
#include <stdbool.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

bool same_file( FILE *a, FILE *b ) {

  int a_fd = fileno( a );
  int b_fd = fileno( b );

  if (a_fd == b_fd) return true;

  struct stat a_stat;
  struct stat b_stat;

  if (fstat( a_fd, &a_stat )) return false;
  if (fstat( b_fd, &b_stat )) return false;

  return (a_stat.st_dev == b_stat.st_dev) && (a_stat.st_ino == b_stat.st_ino);

}

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