Skip to content

Instantly share code, notes, and snippets.

View emadehsan's full-sized avatar
🤸‍♂️
Overthinking about overthinking

Emad Ehsan emadehsan

🤸‍♂️
Overthinking about overthinking
View GitHub Profile
# register this function, so JS code could call this
output.register_callback('notebook.run_algo', run_algo)
# put the JS code in cell and run it
take_photo()
import IPython
import time
import sys
import numpy as np
import cv2
import base64
import logging
from google.colab import output
from PIL import Image
from IPython.display import display, Javascript
from google.colab.output import eval_js
from base64 import b64decode
def take_photo(filename='photo.jpg', quality=0.8):
js = Javascript('''
// ...
// JavaScript code here <<==
// ...
''')
async function takePhoto(quality) {
// create html elements
const div = document.createElement('div');
const video = document.createElement('video');
video.style.display = 'block';
// request the stream. This will ask for Permission to access
// a connected Camera/Webcam
const stream = await navigator.mediaDevices.getUserMedia({video: true});
Processing 1 images
image shape: (425, 640, 3) min: 0.00000 max: 255.00000 uint8
molded_images shape: (1, 1024, 1024, 3) min: -123.70000 max: 151.10000 float64
image_metas shape: (1, 93) min: 0.00000 max: 1024.00000 float64
anchors shape: (1, 261888, 4) min: -0.35390 max: 1.29134 float32
# Load a random image from the images folder
file_names = next(os.walk(IMAGE_DIR))[2]
image = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))
# Run detection
results = model.detect([image], verbose=1)
# Visualize results
r = results[0]
visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'],
# Create model object in inference mode.
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
# Load weights trained on MS-COCO
model.load_weights(COCO_MODEL_PATH, by_name=True)
import os
import sys
import random
import math
import numpy as np
import skimage.io
import matplotlib
import matplotlib.pyplot as plt
# Root directory of the project
async function takePhoto(quality) {
// create html elements
const div = document.createElement('div');
const video = document.createElement('video');
video.style.display = 'block';
// request the stream. This will ask for Permission to access
// a connected Camera/Webcam
const stream = await navigator.mediaDevices.getUserMedia({video: true});
@emadehsan
emadehsan / Test.md
Last active August 14, 2019 13:02
Automatically set cookie in Postman

In the Tests tab of your request, type this code

let cookie = postman.getResponseHeader("Set-Cookie");
postman.setEnvironmentVariable("cookie", cookie);

This will set an environment vairable. In all the requests that need cookie, add to the Request Header

Key: Cookie