Skip to main content

Install python and opencv on the raspberry

Setup Conda and Python and opencv

Setup venv

python -m venv ocv2-env
ocv2-env/bin/pip install opencv-python 

Try python script

import cv2

# Open the default camera
cam = cv2.VideoCapture(0)

# Get the default frame width and height
frame_width = int(cam.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cam.get(cv2.CAP_PROP_FRAME_HEIGHT))

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (frame_width, frame_height))

while True:
    ret, frame = cam.read()

    # Write the frame to the output file
    out.write(frame)

    # Display the captured frame
    cv2.imshow('Camera', frame)

    # Press 'q' to exit the loop
    if cv2.waitKey(1) == ord('q'):
        break

# Release the capture and writer objects
cam.release()
out.release()
cv2.destroyAllWindows()

Add Wayland

export QT_QPA_PLATFORM=xcb

Test

alias py='~/ocv2-env/bin/python'
py record4.py

 

python -m venv ocv2-env

Setup conda 

Did not get opencv working under conda

Download miniforge 

/proc/cpuinfo | grep Model

Wget the installer (take 64 bit, ARM)

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh
  

Run the installer

bash Miniforge3-Linux-aarch64.sh

Test the installation

miniforge3/condabin/conda --version

Add to path

Add export PATH=$PATH:~/miniforge3/condabin to ~/.bashrc
Reload .bashrc
 

Setup conda

conda env list
conda create -n ocv
conda init
Restart conda shell 
conda activate ocv
conda install -c conda-forge descartes folium plotly_express opencv IPython moviepy
conda init
Verify python
python --version

Comments

Popular posts from this blog

SSL handshake failed: Secure connection truncated

Got this problem on Ubuntu 9.10 and 10.10. svn co --username=xx https:/yy zz “SSL handshake failed: Secure connection truncated” According to this link bug-ubuntu The solution is: sudo apt-get install libneon27 cd /usr/lib/ sudo rm libneon-gnutls.so.27 sudo ln -s /usr/lib/libneon.so.27 libneon-gnutls.so.27

Interactive selenium testing

The problem Location of elements When I started using selenium, I noticed that it is not easy to do it right. First you start with IDE, but you notice, that the IDE does not really record a lot. In a next step I added firebug, and started analyzing how the elements where to be located: either by tag, id, class etc. Junit testcase With this information I could then create my junit testcase: @Test public void testMapView() throws Exception { //assert that we cannot see submenu of MapCreator elem = driver.findElement(By.className(SeleniumConstants.MAP_SUB_MENU)); String style = elem.getAttribute("style"); assertTrue("Element must have style display off.",style.matches("display: none.*")); logger.debug("Located element " + SeleniumConstants.MAP_SUB_MENU); //find menu and click on mapview elem = driver.findElement(By.id(SeleniumConstants.MAP_CONTROL)); actions.moveToElement(elem).click().perform(); //assert su...

Run jmeter from eclipse

Download jmeter source and binaries: http://archive.apache.org/dist/jakarta/jmeter/binaries/jakarta-jmeter-2.3.4.zip http://archive.apache.org/dist/jakarta/jmeter/source/jakarta-jmeter-2.3.4_src.zip Unpack jmeter source file, and rename eclipse.classpath into .classpath. Add a .project file to the same directory: <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>jakarta-jmeter-2.3.4</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription> Now import the source code as eclipse project. Add all libs of binary distribution (lib/*.jar) to the new project's lib dir....