Skip to content

Instantly share code, notes, and snippets.

View Merwanski's full-sized avatar
:electron:
Focusing

Merwanski

:electron:
Focusing
  • Belgium
  • Belgium
View GitHub Profile
@Merwanski
Merwanski / opencv_rstp.py
Created May 12, 2022 19:43
opencv-python_connect_to_android_camera_via_rstp
import cv2
import numpy as np
from matplotlib import pyplot as plt
import os
"""
source: https://medium.com/@nhancv/opencv-python-connect-to-android-camera-via-rstp-9eb78e2903d5
NB: Did not work on windows 10
"""
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;0"
@Merwanski
Merwanski / conda_env_creation
Created May 11, 2022 20:35
conda python env creation
# Create The Sandbox You Play In
conda create --name your_env_name python=3.7 -y
conda create --name your_env_name python=3.7 scipy=0.15.0 astroid babel
conda env export > my_environment.yml
conda info --envs
conda activate your_env_name
@Merwanski
Merwanski / keras_data_augmentation.py
Created April 22, 2022 18:04
keras_data_augmentation
# Importing necessary functions
from keras.preprocessing.image import ImageDataGenerator,
array_to_img, img_to_array, load_img
# Initialising the ImageDataGenerator class.
# We will pass in the augmentation parameters in the constructor.
datagen = ImageDataGenerator(
rotation_range = 40,
shear_range = 0.2,
zoom_range = 0.2,
@Merwanski
Merwanski / reduce_vertex_number_PyMeshLab.py
Created March 4, 2022 23:19
How to use PyMeshLab to reduce vertex number to a certain number
import pymeshlab as ml
ms = ml.MeshSet()
ms.load_new_mesh('input.ply')
m = ms.current_mesh()
print('input mesh has', m.vertex_number(), 'vertex and', m.face_number(), 'faces')
# Target number of vertex
TARGET=10000
@Merwanski
Merwanski / cv_bridge_alternative.py
Created February 23, 2022 23:06
Alternative for the `cv_bridge` python library two most used functions.
# initial code from https://github.com/ros-perception/vision_opencv/blob/noetic/cv_bridge/python/cv_bridge/core.py
import cv2
import numpy as np
import sensor_msgs
def cv2_to_imgmsg(cvim, encoding="passthrough", header=None):
if not isinstance(cvim, (np.ndarray, np.generic)):
raise TypeError('Your input type is not a numpy array')
# prepare msg
img_msg = sensor_msgs.msg.Image()
@Merwanski
Merwanski / install_docker.sh
Created February 21, 2022 21:55
Install docker
#!/bin/bash
# Installation instructions from https://docs.docker.com/engine/install/ubuntu/
# Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Use the following command to set up the stable repository
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# INSTALL DOCKER ENGINE
@Merwanski
Merwanski / install_docker_with_nvidia.sh
Created February 2, 2022 22:32
How to Install Docker with NVIDIA support
# Docker-CE on Ubuntu can be installed using Docker's official convenience script:
curl https://get.docker.com | sh \
&& sudo systemctl --now enable docker
# Setting up NVIDIA Container Toolkit
# Setup the stable repository and the GPG key:
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
&& curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
@Merwanski
Merwanski / opencv_yolov3.py
Created January 24, 2022 00:25
opencv yolov3 detection
import argparse
import cv2
import numpy as np
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--image", default='samples/image.jpg', help="image for prediction")
parser.add_argument("--config", default='cfg/yolov3.cfg', help="YOLO config path")
parser.add_argument("--weights", default='yolov3.weights', help="YOLO weights path")
parser.add_argument("--names", default='data/coco.names', help="class names path")
@Merwanski
Merwanski / yolo_keras.py
Created January 24, 2022 00:13
yolo image using keras
# import necessary packages
from numpy import expand_dims
from keras.models import load_model
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
import time
import pdb
# load and prepare an image
def load_image_pixels(filename, shape):
@Merwanski
Merwanski / photo2video.py
Last active January 22, 2022 21:30
photo2video.py
import cv2
import numpy as np
import glob
video_file_name = 'project.wmv'
path_to_images = 'path_2_video/*.bmp'
cmpt = 0
for filename in glob.glob(path_to_images):