Ladies and Gentleman, turn your lights on
SourceCode
#!/usr/bin/python import pygame import pygame.camera class Capture(object): a = [] allines = [] found = 0 def __init__(self): self.size = (640,480) # create a display surface. standard pygame stuff self.display = pygame.display.set_mode(self.size, 0) # this is the same as what we saw before self.clist = pygame.camera.list_cameras() if not self.clist: raise ValueError("Sorry, no cameras detected.") self.cam = pygame.camera.Camera(self.clist[0], self.size) self.cam.start() # create a surface to capture to. for performance purposes # bit depth is the same as that of the display surface. self.snapshot = pygame.surface.Surface(self.size, 0, self.display) def get_and_flip(self): # if you don't want to tie the framerate to the camera, you can check # if the camera has an image ready. note that while this works # on most cameras, some will never return true. if self.cam.query_image(): self.snapshot = self.cam.get_image(self.snapshot) # blit it to the display surface. simple! self.display.blit(self.snapshot, (0,0)) pygame.display.flip() def main(self): going = True while going: for event in pygame.event.get() : if event.type == pygame.KEYDOWN : if event.key == pygame.K_SPACE : print "Space bar pressed down." elif event.key == pygame.K_ESCAPE : print "Escape key pressed down." elif event.type == pygame.KEYUP : if event.key == pygame.K_SPACE : del self.a[:] del self.allines[:] elif event.key == pygame.K_ESCAPE : pygame.quit() self.get_and_flip() def get_and_flip(self): self.snapshot = self.cam.get_image(self.snapshot) # threshold against the color we got before crect = pygame.draw.rect(self.display, (255,0,0), (145,105,30,30), 4) #self.ccolor = pygame.transform.average_color(self.snapshot, crect) mask = pygame.mask.from_threshold(self.snapshot, (240, 240, 255), (30, 30, 30)) self.display.blit(self.snapshot,(0,0)) # keep only the largest blob of that color connected = mask.connected_component() # make sure the blob is big enough that it isn't just noise if mask.count() > 100: # find the center of the blob coord = mask.centroid() self.a.append(coord) self.found = 0 else: self.found = self.found+1 #if we not found the threshold color more then 15 times #we create a new line if self.found > 15: self.allines.append(self.a[:]) del self.a[:] l = len(self.a) for i in range(len(self.allines)): if len(self.allines[i]) >1: pygame.draw.aalines(self.display, (255,255,255), 0, self.allines[i], 1) if l > 1: pygame.draw.aalines(self.display, (255,255,255), 0, self.a, 1) pygame.display.flip() pygame.init() pygame.camera.init() x = Capture() x.main()
Happy Hacking
Andreas
Python QT GUI zur OpenAPI (Website Thumbnailer)
Ein guter Freund von mir war so freundlich, ein Python QT Interface zu meiner Website Thumbnailer API zu bauen.
Hier der Sourcecode:
from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtNetwork import * from designs.FetchDialog import Ui_FetchDialog import os,sys class MainClass(QDialog): def __init__(self, parent = None): super(QDialog, self).__init__() QApplication.setStyle(QStyleFactory.create('plastique')) self.layout = Ui_FetchDialog() self.layout.setupUi(self) self.layout.progress.hide() self.layout.btn_save.hide() self.layout.pic.hide() self.connect(self.layout.btn_save, SIGNAL("pressed()"), self.saveDownloadedImage) self.connect(self.layout.btn_get, SIGNAL("pressed()"), self.progressDownload) def progressDownload(self): self.layout.progress.setValue(0) self.layout.progress.show() self.networkmanager = QNetworkAccessManager(); request = QNetworkRequest() url = "http://codejungle.org/api/thumb_get.php?url=%s" % self.layout.url.text() request.setUrl(QUrl(url)) self.reply = self.networkmanager.get(request) self.connect(self.reply, SIGNAL("downloadProgress(qint64,qint64)"), self.updateProgressBar) self.connect(self.networkmanager, SIGNAL("finished(QNetworkReply *)"), self.showThumbnail) def showThumbnail(self, replyFromServer): if(replyFromServer.isFinished() == True): imageData = replyFromServer.readAll() if(imageData.size() == None): print "Error while reading image!" pixmap = QPixmap() pixmap.loadFromData(imageData) self.originalPixmap = pixmap if(pixmap.width() > 800): pixmap = pixmap.scaledToWidth(800) self.layout.pic.setPixmap(pixmap) self.layout.pic.setMaximumHeight(600) self.layout.pic.setMaximumWidth(800) self.layout.pic.show() self.layout.btn_save.show() replyFromServer.deleteLater() def saveDownloadedImage(self): saveTo = QFileDialog.getSaveFileNameAndFilter(parent=None, caption=QString(), directory = QString(), filter = "Images (*.png)") if(self.originalPixmap.save(saveTo[0], "png")): QMessageBox.information(self, "Success!", "Your image is now saved!") self.layout.pic.hide() self.layout.btn_save.hide() self.resize(530, 132) def updateProgressBar(self, bytesRecieved, bytesTotal): self.layout.progress.setMaximum(bytesTotal) self.layout.progress.setValue(bytesRecieved) if(self.layout.progress.value() == bytesTotal): self.layout.progress.hide() if __name__ == "__main__": app = QApplication([]) software = MainClass() software.show() app.exec_()
Known Bugs:
Vielen Dank an Mario (www.unite-it.at) an dieser Stelle.
Andreas
Schon wieder Omas Geburtstag vergessen?
Der Arzttermin war doch am Montag, oder war es doch Dienstag?
Was war noch mal die wichtige Sache, die ich heute unbedingt noch machen wollte?
Und wann fängt eigentlich das Meeting an?
Peinliche Situationen, die man sich mit meinem neuen Reminder Service
ersparen kann.
Der Sourcecode ist wie immer OpenSource, doch müsst
ihr euch noch ein paar Wochen gedulden.
Ich möchte zuerst sicherstellen, dass der Reminder Service
auch wirklich stabil läuft und dafür brauch ich möglichst viele Betatester.
Wenn du mir dabei helfen magst kannst du Remind ME hier testen:
http://www.codejungle.org/reminder/
LG
Andreas
Boersenspiel in php zum gratis Download
Weil ich öfter gefragt worden bin ob ich mein Börsenspiel zum Download freigeben kann,
habe ich mich entschlossen es nun unter der GPL2 zu veröffentlichen.
Jeder der es testen mag kann das hier tun: Börsenspiel (beta) Demo
Jeder der es downloaden möchte kann das hier machen:
svn co svn://codejungle.org/boersenspiel
Die alte Version ist weiterhin unter
http://www.codejungle.org/code/boersenspiel.tar.bz2 erreichbar.
Achtung die alte Version unter boersenspiel.ath.cx ist nicht mehr erreichbar !!
Ich empfehle aber die Beta zu verwenden, da der alte Sourcecode nicht weiter gewartet wird.
Ausserdem ist die Entwicklung am neuen System schon sehr weit vorgeschritten.
Wer sich ander Entwicklung beteidigen mag, kann es hier tun:
http://www.codejungle.org/redmine/projects/boersenspiel
Der Sourcecode ist relativ straight forword gecodet.
Was evtl. interessant ist, es gibt zwei Arten wie die Börsendaten
aggregiert werden.
1. Yahoo Finance (generate2.php)
2. Random (generate.php)
Ich würde die zweite Variante empfehlen, da die Daten von Yahoo sich nur alle 15 Min. ändern und
dann meist auch nicht viel.
Das Gameplay ist auf jeden Fall bei der zweiten Variante interessanter und man hat als Entwickler auch
mehr Möglichkeiten.
Ich wünsch euch viel Spass beim Brokern und würde mich über
Verbesserungsvorschläge sehr freuen.
LG
Andreas
Gesichtserkennung mit Openvc und meiner API
Ich möchte hier eine weitere Funktion meiner API kurz vorstellen.
Es handelt sich um eine Gesichtserkenungs API, mit der man zum Beispiel
eine grosse Anzahl von Bildern schnell und einfach sortieren kann oder aber
sicherstellen kann, dass auf einem hochgeladenen Profilbild ein Gesicht zu sehen ist.
Code
<?
/**
* Face detection
*
*
* @param $image string should be the path to your jpeg
*
* @return string xml output of my api
*
* @author andreas beder <office@codejungle.org>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
**/
function face_detection($image){
$data = array('face' => '@'.$image);
$Curl_Session = curl_init('http://www.codejungle.org/api/face.php');
curl_setopt ($Curl_Session, CURLOPT_POST, 1);
curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, $data);
curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($Curl_Session, CURLOPT_RETURNTRANSFER, 1);
$response=curl_exec($Curl_Session);
curl_close ($Curl_Session);
return $response;
}
?>