Issue 1:
System information (version)

OpenCV => 4.1.2

-- General configuration for OpenCV 4.1.2 =====================================
-- Version control: unknown
--
-- Platform:
-- Timestamp: 2019-10-27T07:15:40Z
-- Host: Linux 5.3.6-1-MANJARO x86_64
-- CMake: 3.15.4
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: Release
--

Docker image running Alpine Linux Edge, gcc 9.2.0, cmake

[ 39%] Linking CXX executable ../../bin/opencv_version
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../../lib/libopencv_core.so.4.1.2: undefined reference to `cblas_sgemm'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../../lib/libopencv_core.so.4.1.2: undefined reference to `cblas_zgemm'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../../lib/libopencv_core.so.4.1.2: undefined reference to `cblas_cgemm'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../../lib/libopencv_core.so.4.1.2: undefined reference to `cblas_dgemm'

I think cmake should error or not compile that module if CBLAS is not found.

Issue 2:
System information (version)

opencv-python version => 4.2.0.32

Operating System / Platform => Windows 64 Bit

Detailed description

I think there is a bug when using cv2.UMat with cv2.calcOpticalFlowPyrLK.

When running the code taken from https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_video/py_lucas_kanade/py_lucas_kanade.html , it works as expected.

However, after attempting to use cv2.UMat with it, the points are scaled smaller with each frame as seen in the pictures on the left below. The right side pictures are obtained without using cv2.UMat (points drawn in green).

Also, I noticed that changing maxLevel seems to affect the rate at which the points are scaled. Multiplying the new points by the value gives the correct position but after running for a while the points disappear.

maxLevel = 0, pts are 2 times smaller than expected

maxLevel = 1, pts are 4 times smaller than expected

maxLevel = 2, pts are 8 times smaller than expected

I've tried using other versions of opencv-python such as 4.0.0.21 or 3.4.9.21 which produced the same results.

Steps to reproduce

import numpy as np
import cv2

cap = cv2.VideoCapture('traffic_video.mp4')

# params for ShiTomasi corner detection
feature_params = dict( maxCorners=100,
qualityLevel=0.03,
minDistance=7,
blockSize=7)

# Parameters for lucas kanade optical flow
lk_params = dict( winSize=(15,15),
maxLevel=0,
criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03))

# Take first frame and find corners in it
ret, old_frame = cap.read()
old_frame = cv2.UMat(old_frame)
old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
p0 = cv2.goodFeaturesToTrack(old_gray, mask=None, **feature_params)
p0 = cv2.UMat(np.array(sorted(p0.get(), key=lambda p: tuple(p[0]))))

while(1):

ret,frame = cap.read()
frame = cv2.UMat(frame)
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Calculate optical flow
p1, st, err = list(map(lambda umat: umat.get(), cv2.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params)))

for i in p1:
x, y = i.ravel()
cv2.circle(frame, (x, y), 4, (0, 0, 255), -1)
good_new = p1[st == 1]
p0 = cv2.UMat(good_new.reshape(-1, 1, 2))
old_gray = frame_gray
cv2.imshow('frame',frame)
k = cv2.waitKey(0) & 0xff
if k == 27:
break

cv2.destroyAllWindows()
cap.release()