Threading within a GUI and OpenCV

2013-04-03 Thread Sam Berry
Hey, 

I'm fairly new to python, and have had no experience with threading.

Iv made a small GUI App using the kivy module and OpenCV, i have currently got 
a button that when pressed runs a function that records from my webcam for 20 
seconds.

However i have two other buttons, that when pressed i want to stop the 
recording. However when the button to record has been pressed the App freezes 
until the recording function has finished.

I have read that threading can be used to run a function as a deamon? so that 
other functions can be ran simultaneously?

I was just wondering if this would be the way to go, or if there are 
alternative routes? 

A snippet from my code can be seen at (http://pastebin.com/9uFRjkgV) with a 
failed attempt of using threading!

Any help would be appreciated.

Thanks, Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python class and variable issue(newby question!)

2013-03-29 Thread Sam Berry
Thanks for the responses! My issue was sorted with Benjamins post, just 
printing s worked.

Cheers for the info though Chris, if i have any further issues il post them 
with some working code.

Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


Python class and variable issue(newby question!)

2013-03-29 Thread Sam Berry
Hey, 

Im new to object orientated programming and have an issue with using classes. 
Im using the kivy module, a GUI creator , so posting the actual code may 
confuse. But an example of what im trying to achieve is below

class test()
s = 1

def test1()
global s
s = 2

def test2()
global s
s = 3

def test3()
global s
s = 4


class test4()

def printing()
print test().s

After been in the test()class  a choice of buttons allows the user to run 
either of the functions within it and sends us into the test4() class. Then 
another button runs printing().

However printing() always prints 1, even if the variable has been changed. Im 
guessing because  print test().s  redefines the variable. May be a very simple 
to solve problem, but i cant figure it out.

Any insights of how to get this working, or example code would be very helpful!

Thanks, Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recording live video stream from IP camera issue

2013-02-18 Thread Sam Berry
Thanks for the advice! I looked into it, seems using windows was an issue, 
switched to ubuntu and it worked! 

Just wondering if you have used opencv for recording purposes?

Or if you know of any python documentation for opencv2?

Information is hard to come by!

Thanks again, Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recording live video stream from IP camera issue

2013-02-17 Thread Sam Berry
Hi Xav,

Iv been looking into OpenCV, i can easily stream my laptops webcam using this 
code.

import cv2

cv2.namedWindow("preview")

vc = cv2.VideoCapture(0)

if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False

while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break

However using the cv2.Videocapture(ip_address) method will not load my IP 
camera video feed into the new window. I can view the stream in any web browser 
or VLC using the IP address
http://192.168.1.72:1025/videostream.cgi?user=&pwd=&resolution=8.

Did you have this issue? Is there some lines of code i may need to add?

Any help would be appreciated!

Thanks, Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


OpenCV and WIFI IP Camera Issue

2013-02-14 Thread Sam Berry
Hey,

Iv installed OpenCV on my windows machine. I can successfully view the camera 
stream from my laptop so the installation was successful. However when i edited 
the code adding in the address of my IP camera like so

import cv2

cv2.namedWindow("preview")
vc = 
cv2.VideoCapture('http://192.168.1.72:1025/videostream.cgiUSERNAMEANDPASSWORD')

if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False

while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break

When run, python tries to open the window to display the camera feed then 
closes  before displaying the feed. Anyone have any ideas why? I read somewhere 
that there is an issue with this been run on windows?

Any insight would be appreciated! Im all googled out.

Thanks, Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recording live video stream from IP camera issue

2013-02-06 Thread Sam Berry
Hi, 

This is for a university project.

My issue is that i have built an App using pythons Kivy module, and i need to 
be able to stream and record from an IP camera upon request.

I have just used the VLC.exe to stream the video feed. But it is the recording 
i am having problems with.

I'l look into OpenCV, thanks for the help!

Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recording live video stream from IP camera issue

2013-02-06 Thread Sam Berry
Thank you for the quick reply!

I found this code just from multiple google searches, but yer it mentioned 
online video streaming, however my IP camera would be streaming in Mjpeg format 
(I thought been able to convert between the two formats seemed way to easy!)

So i'm guessing its just 20mb of a picture and then nothing.

Could you give any insight into how to record an mjpeg stream? External 
libraries for me to consider etc?

Thanks, Sam
-- 
http://mail.python.org/mailman/listinfo/python-list


Recording live video stream from IP camera issue

2013-02-06 Thread Sam Berry
Hey,

I have no vast knowledge of python, but i came across this code to capture 
video from my IP camera

import urllib2
import time
import logging

print "Recording video..."
response = urllib2.urlopen("IP Address")
filename = time.strftime("%Y%m%d%H%M%S",time.localtime())+".avi"
f = open(filename, 'wb')

video_file_size_start = 0
video_file_size_end = 1048576 * 20  # end in 20 mb
block_size = 1024

while True:
try:
buffer = response.read(block_size)
if not buffer:
break
video_file_size_start += len(buffer)
if video_file_size_start > video_file_size_end:
break
f.write(buffer)

except Exception, e:
logging.exception(e)
f.close()

This code works, however when i try to playback the .avi file in VLC player 
(file wont open in any other media player) it just flashes an image instead of 
a video file, even though the .avi file is around 20mb.

Is there some extra lines of code i need to include or change? Perhaps a timing 
option instead of a file size?

Any help or insight would be much appreciated!!

Thanks, Sam
-- 
http://mail.python.org/mailman/listinfo/python-list