OpenCV

Why removing waitKey() in openCV doesn't work?

泪湿孤枕 提交于 2021-02-19 05:25:11
问题 I'm starting out with OpenCV with Python 3 and I have the following snippet: import cv2 video = cv2.VideoCapture(0) while True: success, captured_frame = video.read() cv2.imshow('Video', captured_frame) pressed_key = cv2.waitKey(1) & 0xFF if pressed_key == ord('q'): break video.release() cv2.destroyAllWindows() If I remove the pressed_key variable along with its condition, the program runs but the Video window is blank and Windows attempts to force quit the program. Why is that? 回答1: opencv

Change real camera resolution in OpenCV

天大地大妈咪最大 提交于 2021-02-19 03:40:19
问题 I'm trying to take 4k pictures using OpenCV, but when I change the resolution, the pictures just look resized instead of better quality. I'm using OpenCV version 4, Python 3.6, Logitech BRIO 4k webcam and Windows 10. If I don't change the camera resolution, it defaults to 640 x 480. If I change the resolution, the pictures just look blurred like they have been resized and not actually better quality. I can use the "Camera" app on Windows 10 to verify that the camera works with 4k resolution.

How to OCR image with Tesseract

浪子不回头ぞ 提交于 2021-02-19 03:33:12
问题 I am starting to learn OpenCV and Tesseract, and have trouble with what seems to be a very simple example. Here is an image that I am trying to OCR, that reads "171 m": I do some preprocessing. Since blue is the dominant color of the text, I extract the blue channel and apply simple thresholding. img = cv2.imread('171_m.png')[y, x, 0] _, thresh = cv2.threshold(img, 150, 255, cv2.THRESH_BINARY_INV) The resulting image looks like this: Then throw that into Tesseract, with psm 7 for single line:

How to mask image with binary mask

与世无争的帅哥 提交于 2021-02-19 02:40:21
问题 Suppose I have a greyscale image here: And a binary masked image here: With the same dimensions and shape. How do I generate something like this: Where the values indicated by the 1 in the binary mask are the real values, and values that are 0 in the mask are null in the final image. 回答1: Use cv2.bitwise_and to mask an image with a binary mask. Any white pixels on the mask (values with 1) will be kept while black pixels (value with 0) will be ignored. Here's a example: Input image (left),

VideoCapture() opencv python pyinstaller not opening

99封情书 提交于 2021-02-19 02:35:27
问题 I am trying to produce an .exe of a simple GUI made with PyQt4 in python 2.7 using pyinstaller to play a video. Here are the details of my problem: Simple layout with two buttons, one to load video, other to play video. In my IDE, the video loads and plays perfectly. The video pops up in another window and closes when it is over. After running pyinstaller on the program, the GUI interface pops up after running the .exe. The open file dialog works correctly, however the video will not play. In

setting opencv video to fullscreen android

空扰寡人 提交于 2021-02-19 02:33:10
问题 i am trying to set a video to fullscreen using opencv. the input is coming from the camera. it shows on the screen in the center but not as full screen. relevant code: public class Sample3Native extends Activity implements CvCameraViewListener { private static final String TAG = "OCVSample::Activity"; private Mat mRgba; private Mat mGrayMat; private Mat mFinalMat; private CameraBridgeViewBase mOpenCvCameraView; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {

C++/OpenCV - Kalman filter for video stabilization

邮差的信 提交于 2021-02-19 02:25:08
问题 I try to Stabilize video with a Kalman filter for smoothing . But i have some problems Each time, i have two frames: one current and another one. Here my workflow: Compute goodFeaturesToTrack() Compute Optical Flow using calcOpticalFlowPyrLK() Keep only good points Estimate a rigid transformation Smoothing using Kalman filter Warping of the picture. But i think there is something wrong with Kalman because at the end my video is still not stabilized and it's not smooth at all, it even worse

Convert RGB array to Mat (OpenCv)

蹲街弑〆低调 提交于 2021-02-19 02:11:20
问题 I've been trying to convert an array [R,G,B,..] in Mat object with opencv. But is returning wrong data, someone knows why? double data[12] = {0,0,255,0,0,255,0,0,255,0,0,255}; Mat src = Mat(2,2, CV_16UC3, data); and returns: M = [0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 57344, 16495] EDIT: Solved! use uchar instead double, and CV_8UC3 回答1: i think, you wanted: uchar data[12] = {0,0,255,0,0,255,0,0,255,0,0,255}; Mat src = Mat(2,2, CV_8UC3, data); (all red, 2x2 rbg image) 来源: https://stackoverflow.com

Convert RGB array to Mat (OpenCv)

吃可爱长大的小学妹 提交于 2021-02-19 02:09:00
问题 I've been trying to convert an array [R,G,B,..] in Mat object with opencv. But is returning wrong data, someone knows why? double data[12] = {0,0,255,0,0,255,0,0,255,0,0,255}; Mat src = Mat(2,2, CV_16UC3, data); and returns: M = [0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 57344, 16495] EDIT: Solved! use uchar instead double, and CV_8UC3 回答1: i think, you wanted: uchar data[12] = {0,0,255,0,0,255,0,0,255,0,0,255}; Mat src = Mat(2,2, CV_8UC3, data); (all red, 2x2 rbg image) 来源: https://stackoverflow.com

Convert RGB array to Mat (OpenCv)

别来无恙 提交于 2021-02-19 02:07:01
问题 I've been trying to convert an array [R,G,B,..] in Mat object with opencv. But is returning wrong data, someone knows why? double data[12] = {0,0,255,0,0,255,0,0,255,0,0,255}; Mat src = Mat(2,2, CV_16UC3, data); and returns: M = [0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 57344, 16495] EDIT: Solved! use uchar instead double, and CV_8UC3 回答1: i think, you wanted: uchar data[12] = {0,0,255,0,0,255,0,0,255,0,0,255}; Mat src = Mat(2,2, CV_8UC3, data); (all red, 2x2 rbg image) 来源: https://stackoverflow.com