# Live cam

Next, we want to configure a live cam connected to the Raspberry. With a cam, there can be multiple applications:

* 24h live stream of whatever. Exposing a port in the local network should suffice.
* Take a picture at a certain point of the day and save it. Then, timelapse can be done.

source:&#x20;

To use cv2:

* Create virtual environment `python3 -m venv venv`
* Activate it `. venv/bin/activate`
* Install cv2 `pip install opencv-python`
* Install extra libs required `sudo apt-get install libatlas-base-dev`
* Run following script

```python
import cv2
import time

cap = cv2.VideoCapture(0)
ret, frame = cap.read()

def takePicture():
    (grabbed, frame) = cap.read()
    showimg = frame
    # cv2.imshow('img1', showimg)  # display the captured image
    cv2.waitKey(2000)
    #time.sleep(1) # Wait 300 miliseconds
    image = 'test-image.png'
    cv2.imwrite(image, frame)
    cap.release()
    return image

print(takePicture())
```

Play with waitKey(\*) to let some seconds to focus light. Also, adjust cam.

{% hint style="info" %}
<https://github.com/opencv/opencv-python>

<https://raspberrypi-guide.github.io/electronics/using-usb-webcams>

<https://stackoverflow.com/questions/53347759/importerror-libcblas-so-3-cannot-open-shared-object-file-no-such-file-or-dire>

<https://gist.github.com/Luxato/384a7c8a6bfdeba09d54cb5bd6b2c9fb>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.lcsrg.me/home-setup/raspberry/live-cam.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
