Features of the mjpeg Server:
- Can show html files from the local directory
- Can show jpeg images from the local directory
- Can serve multiple client simultaniously with a mjpeg stream ( multithreaded )
- Image Quality of the stream can be set by the client.
The Stream can be watched in a Browser or by e.g. VLC-player by opening the url:
In order to get the Streamquality adjusting interface open in a browser with:
(index.html must exist in the directory where the server is executed. The content of index.html is shown below)
- Python with OpenCV and webcam
The Webserver .py file:
#edited by Norbert (mjpeg part) from a file from Copyright Jon Berg , turtlemeat.com, #MJPEG Server for the webcam import string,cgi,time from os import curdir, sep from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from SocketServer import ThreadingMixIn import cv import re capture = cv.CaptureFromCAM(-1) img = cv.QueryFrame(capture) cameraQuality=75 class MyHandler(BaseHTTPRequestHandler): def do_GET(self): global cameraQuality try: self.path=re.sub('[^.a-zA-Z0-9]', "",str(self.path)) if self.path=="" or self.path==None or self.path[:1]==".": return if self.path.endswith(".html"): f = open(curdir + sep + self.path) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) f.close() return if self.path.endswith(".mjpeg"): self.send_response(200) self.wfile.write("Content-Type: multipart/x-mixed-replace; boundary=--aaboundary") self.wfile.write("\r\n\r\n") while 1: img = cv.QueryFrame(capture) cv2mat=cv.EncodeImage(".jpeg",img,(cv.CV_IMWRITE_JPEG_QUALITY,cameraQuality)) JpegData=cv2mat.tostring() self.wfile.write("--aaboundary\r\n") self.wfile.write("Content-Type: image/jpeg\r\n") self.wfile.write("Content-length: "+str(len(JpegData))+"\r\n\r\n" ) self.wfile.write(JpegData) self.wfile.write("\r\n\r\n\r\n") time.sleep(0.05) return if self.path.endswith(".jpeg"): f = open(curdir + sep + self.path) self.send_response(200) self.send_header('Content-type','image/jpeg') self.end_headers() self.wfile.write(f.read()) f.close() return return except IOError: self.send_error(404,'File Not Found: %s' % self.path) def do_POST(self): global rootnode, cameraQuality try: ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) if ctype == 'multipart/form-data': query=cgi.parse_multipart(self.rfile, pdict) self.send_response(301) self.end_headers() upfilecontent = query.get('upfile') print "filecontent", upfilecontent value=int(upfilecontent) cameraQuality=max(2, min(99, value)) self.wfile.write("<HTML>POST OK. Camera Set to<BR><BR>"); self.wfile.write(str(cameraQuality)); except : pass class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): #class ThreadedHTTPServer(HTTPServer): """Handle requests in a separate thread.""" def main(): try: server = ThreadedHTTPServer(('localhost', 8080), MyHandler) print 'started httpserver...' server.serve_forever() except KeyboardInterrupt: print '^C received, shutting down server' server.socket.close() if __name__ == '__main__': main()
The index.html file:
<HTML> <BODY> <div id="hiddenDiv" style="display:none;visible:hidden;"> < iframe src="hidden.html" height="1" width="1" border="0" scrolling="no" name="hiddenFrame" id="hiddenFrame" >< / iframe> </div> <img src="camera.mjpeg" alt="Smiley face" height="480" width="640"> <form target="hiddenFrame" method='POST' enctype='multipart/form-data'> <div align="center"> Set Quality: <select name="upfile" width="50"> <option value="2"> 2 </option> <option value="5"> 5 </option> <option value="10"> 10 </option> <option value="20"> 20 </option> <option value="30"> 30 </option> <option value="50"> 50 </option> <option value="75"> 75 </option> <option value="80"> 80 </option> <option value="90"> 90 </option> <option value="96"> 96 </option> </select> <input type=submit value=Set> </div> </form> </BODY> </HTML>
Ok there are two implementations. The implementation basically does a data mapping of 88 random 11 bit wide indata values to 88, 11 bit wide outdata values. Everything is done combinatorically.
The first implemntation looks like this:
case indata is
when “11100000001″ => outdata<=”10000110111″;
when “10000110111″ => outdata<=”00001011001″;
…….(86 more mappings)
when others => outdata<=”———–”;
And the second one implents the same thing with exactly the same numbers but uses an alternative statement:
outdata <= “10000110111″ when indata=”11100000001″ else
“00001011001″ when indata=”10000110111″ else
………………(85 more mappings)
“11110110011″ when indata=”00001000001″ else
To make the story short, here is the result from Quartus v11.1 :
First implemntation with case is:
Total logic elements : 261 / 33,216 ( < 1 % )
Second implemntation with when else:
Total logic elements : 932 / 33,216 ( 3 % )
Yes thats quite creapy. Thats nearly 4 times as much logic.
I recently i tried to compress some random numbers. The idea was to use hierarachical state maschine to generate the random looking data from them. To do this i would need to generate the transistion logic of the state maschinne out of the random data. I thought KV-Diagramms or the quine mccluskey algorithm should work since they minimize the logic function.
As i know modern synthesis tools use these technics, so i just thought, why not put the combinatorical transition logic of some random numbers into a vhdl description and see how many LUT4′s (each 16 bits) it would take.
What i ended up doing was compering and wondering the synthesis result between the VHDL:
when else statment and the case is statment. (Results in the next blog)
The video can probably show some of the potential of electrostatic field sensing.
The first Operational amplifier has a very high input resistance
Explanation and thoughts:
Measurment of the environment with extrem high Impedance value. The values form the operational amplifiers are sampled with the at90usb1287 (microcontroller) ADC and are send via USB to the computer. Python and mathplotlib is used to display the values at the screen in realtime.
The blue thing which i swing around is a ordinary rope. The rope is not connected to the computer in any way other than the coupling through the electric field in the environment. (well also through the air and preassure waves)
The sensor dont seems to respond to magnetic fields.
If you want you can probably say it is a electric scalar wave transmission system.
Since the rope always carries some residual charges. Swinging it creates charge fluctuations in the environmental field. No charges are exchanged! The sensor plate is insulated.
It seems to create a electric compression wave which compresses and expands every charge/Atom/electron? around in the environment. It seems quit similar to a sound wave but more of electrical nature.
Inside the house or outside beneath a high voltage transmission line i always meassure a 50Hz sinewave base signal from the main line (In this test te notebook runs on battery, so no direkt connection to the 50 Hz line). These waves seem to compress and expand also all the charges in our body all the time. Thats probably the reason why i feel so calm when there is a power blackout. The same calmness appears to me when i am in the forest or under a tree. And the cool thing which supports my feelings, is that i was not able to measure the 50Hz signal in the forest or under a tree. Trees seem to block or absorb these electric compression waves at 50 Hz.
I therefore conclude that the 50 Hz main lines, which are basically installed in every house are not good for my well beeing.
So what should i prefer? Live in a house where i feel as well as when i take a walk through the forest, or live my complete live in a house where i always get this small slight hardly recogniseable unpleasant feeling?
The solution ? I don’t know yet, anyway
If you have the first satisfying answer to the Question for the following video i will reward you with 10 Euros. (no joke)
Why is the magnet turning upwards in free fall and not in the direction of the north pole?
Is the magnet pushing against the aether? Has it todo with the earth electrostatic field? Is it some interaction with the earth magnetic field? Is this violating F= m*g ?
Try it -> it is really fascinating!
If the answer isnt answered in three weeks i will add another 10 Euros to the budget. I also hope for some ideas on how to exploit this effect in a device.
Here i show a simple system i built to track the Sun passing the sky. Some people call it Sun tracking, but i dont like it because it suggest that the Sun is moving. Yeah the sun is indeed moving, but it is not what is tracked.
Electrical parts used:
1 x Photoresitor, 1 x Transistor, 1 x Solarpanel, 1 x Operational amplifier, 2x Potentiometers, 1 x Motor with gear
If the Photoresistor is under direkt Sunlight the Motor is switched on. This rotates the complete device. This will move the shadow over the Photoresistor. This switches of the Motor.
Running a very small subset of python on an FPGA is now possible. This Python Hardware CPU (written in an hardware description language) can directly execute a very small subset of python bytecode with one bytecode instruction per Clock cycle.
This is a implementation of a kind of a microprocessor in myhdl which can directly execute, very limited python bytecode. This myhdl description of the processor can be converted to standard VHDL. Since myhdl is written in python the CPU programm and some additional (if needed) hardware description can be handled in the same file. This simplyfies designing a lot.
I was able to run the Python Hardware CPU on the lattice pico development board. Soon i will create a additional page with more information on that for more information on the CPU visit here.
The approach is to directly execute python bytecode (but without all the dynamic features of python) where nearly every instruction is executed in one Clock cycle.
In the end i was able to successfully run python code which is as complex as the following.
global_argument=2 def kate(Cycles,argx): global PORTC_OUT,PORTD_OUT x=0 PORTD_OUT=PORTD_OUT+argx while x<Cycles: x=x+1 PORTC_OUT=PORTC_OUT^8 return 2 def delay(Cycles1,Cycles2): global PORTC_OUT x=5 while x<(Cycles1+Cycles2): x=x+1 PORTC_OUT=PORTC_OUT^4 x=0 while x<kate(1,global_argument): PORTC_OUT=PORTC_OUT^2 x=x+1 def CPU_main(): global PORTA_IN,PORTB_IN,PORTC_OUT,PORTD_OUT # at least output ports need to be defined as gloabals x=0 a=7 b=8 var_argument_b=3 var_argument_b=var_argument_b+1 while 1: x=x+1 #funcas(kkt(3)) # calling a function with an function as an argument would not work delay(global_argument,var_argument_b) if PORTA_IN==1: PORTC_OUT=PORTC_OUT^1 if x<20: PORTD_OUT=x elif 20<=x<25: #x>=20 and x<25: #both work PORTD_OUT=(2**6)+x else: PORTD_OUT=x a,b=b,a PORTD_OUT=a<<1
Another interessting approach for example would be to use a standard microcontroller from opencores or etc.., which can execute c or c++ and than use “Shed Skin” or “Pyrex” or to convert the python code to c or c++ and then load it into a microcontroller on an FPGA or so. Probably “Shed Skin” makes use of some heavy libraries which would blow up the hole thing. Just an idea.