Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality for image processing. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions godec_opencv_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#%% Import libraries
import time
import numpy as np

try:
import cv2
except ImportError:
raise ImportError('OpenCV is requires to read video files')

from godec import godec
from utils import *

# Read until video is completed
M = None
height = None
width = None
i = 0

img = cv2.imread("/Users/onyekachukwuokonji/Desktop/godec/dataset/3.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
height, width = img.shape

# flatten the 2-D array, produces a row vector
frame = img.T.reshape(-1)

# convert row vector to column vector
M = np.array([frame]).T

cv2.imshow('frame', frame)

assert M is not None
assert width is not None
assert height is not None

print("Number of frames: ", i, " with size ", (width, height))
print("Processing M with shape ", M.shape)

#%% Decompose
t = time.time()
L, S, LS, _ = godec(M)
elapsed = time.time() - t
print(elapsed, "sec elapsed")

#%% Display results
plot_2d_results(M, LS, L, S, height, width)