bndhealth
Posts: 17
Joined: Fri Mar 20, 2020 9:50 am

Using SENSE HAT and Pi Camera Project possibility of working for school project

Mon May 11, 2020 5:13 am

Hi Guys
Can you please tell me if this idea is possible to do on a school project.
I am using a SENSE HAT and Pi Camera. What I want the code to do is say if the temperature is 35 degrees, it will take a picture every 30 seconds for 2 minutes. But I want the image taken every 30 seconds be compared to the prior image for changes and that should be alerted to the user (i.e. maybe text or colour or image on SENSE hat).

in simple word like my experiment is to see if changes in temperature can affect people movement so if the temperature is high like 35 degress the camera will activate, take pictures say every 30 seconds and it will compare it the previous image for changes in movement (people walking about).

W. H. Heydt
Posts: 12648
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Using SENSE HAT and Pi Camera Project possibility of working for school project

Mon May 11, 2020 5:26 am

It's certainly possible. And--FYI--both the Pis with SenseHATs on the ISS have cameras attached (one normal, one NoIR). As for the image comparisons, how good are your programming skills?

bndhealth
Posts: 17
Joined: Fri Mar 20, 2020 9:50 am

Re: Using SENSE HAT and Pi Camera Project possibility of working for school project

Mon May 11, 2020 5:31 am

I'm not extremely good at Python coding but I know the basics and I am willing to learn.
I havent found any online resources that show me how to compare them so any help would be appreicated.
The only site I found was this:
https://medium.com/@theoremco/motion-de ... 6f4e3cd9a6

My only inquiry is what libraries should I refer to before I run the code in this example?

Code: Select all

threshold = 10
sensitivity = 20

def captureFrame():
  command = "raspistill -w %s -h %s -t 0 -e bmp -o -" % (100, 75)
  imageData = StringIO.StringIO()
  imageData.write(subprocess.check_output(command, shell=True))
  imageData.seek(0)
  im = Image.open(imageData)
  buffer = im.load()
  imageData.close()
  return im, buffer
  
### Capture the first frame
image1, buffer1 = captureFrame()
  
while (True):
  # Capture a second frame
  image2, buffer2 = captureFrame()
  
  # Calculate difference
  changedPixels = 0
  for x in xrange(0, 100):
    for y in xrange(0, 75):
      # Just check green channel as it's the highest quality channel
      diff = abs(buffer1[x,y][1] - buffer2[x,y][1])
      if diff > threshold:
        changedPixels += 1
        
  if changedPixels > sensitivity:
    lastCapture = time.time()
    # Capture full picture if threshold is reached
    saveImage(1280, 960)
    
  # Swap the buffers for the next frame comparison
  image1 = image2
  buffer1 = buffer2

User avatar
bensimmo
Posts: 4622
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Using SENSE HAT and Pi Camera Project possibility of working for school project

Mon May 11, 2020 7:40 am

Have you got the basics going first.
You'll be able to find out the SenseHAT and Camera from the RaspberryPi Learning section.
it's easy one you get use to them.

get the going am saving you pictures.

Once that is done, look at comparing them you'll now more about how they work by then
Picamera and Sensehat are the two Python3 modules you'll probably be using.
They are well documented.
Once you hit the advanced part of picamera it get more complicated, but you have numpy arrays and motion vectors, opencv and things to play with. But they give example of use.
But get the basic working first.

The Pi is more powerful than your task, you can probably compare a lot quicker

https://picamera.readthedocs.io
https://pythonhosted.org/sense-hat/


note, that code you posted is python2, you want to be using Python3 now.
and for analysis, I think numpy module will be quicker than the for loops.


(note I haven't use either of them, bar the SenseHAT a lot)

Return to “General discussion”