OpenCV

How to implement .dat file for handwritten recognition using SVM in Python

萝らか妹 提交于 2021-01-28 06:35:27
问题 I've been trying to train Hand-written Digits using SVM based on the code on OpenCV library. My training part is as follow: import cv2 import numpy as np SZ=20 bin_n = 16 svm_params = dict( kernel_type = cv2.SVM_LINEAR, svm_type = cv2.SVM_C_SVC, C=2.67, gamma=5.383 ) affine_flags = cv2.WARP_INVERSE_MAP|cv2.INTER_LINEAR def deskew(img): m = cv2.moments(img) if abs(m['mu02']) < 1e-2: return img.copy() skew = m['mu11']/m['mu02'] M = np.float32([[1, skew, -0.5*SZ*skew], [0, 1, 0]]) img = cv2

display video on python without opencv?

天涯浪子 提交于 2021-01-28 05:42:28
问题 I am using openCv for making video processing. What I do is reading a video frame by frame, then applying some processing on each frame and then displaying the new modified frame. My code looks like that : video_capture = cv2.VideoCapture('video.mp4') while True: # Capture frame-by-frame ret, frame = video_capture.read() # Applying some processing to frame . . . # Displaying the new frame with processing img=cv2.imshow('title', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break This way I can

Opencv2: Python: cv2.VideoWriter

萝らか妹 提交于 2021-01-28 05:23:21
问题 Why does the following code not save the video? Also is it mandatory that the frame rate of the webcam matches exactly with the VideoWriter frame size? import numpy as np`enter code here import cv2 import time def videoaufzeichnung(video_wdth,video_hight,video_fps,seconds): cap = cv2.VideoCapture(6) cap.set(3,video_wdth) # wdth cap.set(4,video_hight) #hight cap.set(5,video_fps) #hight # Define the codec and create VideoWriter object fps = cap.get(5) fourcc = cv2.VideoWriter_fourcc(*'XVID')

Why morphological opening displace my image?

﹥>﹥吖頭↗ 提交于 2021-01-28 05:21:56
问题 I have a picure from a microscope. I want to quantify the number of cellular nucli (blue ovals - see picture original image) For that I am using Python 2.7 with OpenCV3. First, I load the image in BGR, and extract the blue layer import cv2 import numpy as np img = cv2.imread('image.jpg',1) img_gray = img[:,:,0] Next, I produce the BINARY image and then I applied morphological opening, filling and measured contours (see picture: GRAY-after thresholding, OP-n:after opening n times, 'filling

I am trying to measure land plot area Using OpenCV in Python

删除回忆录丶 提交于 2021-01-28 05:14:46
问题 SO far I have been able to perform medianBlur and Edge Detection, Now I want to o further remove noise from the image, Matlabs region **property functions ** was used to remove all white regions that had a total pixel area of less than the mean pixel area value. How can I implement this on python import matplotlib.image as mpimg import numpy as np import cv2 import os import math from collections import defaultdict from matplotlib import pyplot as plt import imutils #import generalized_hough

How to stitch an array of images into an MxN image collage

早过忘川 提交于 2021-01-28 05:13:34
问题 So I have an array of Mat objects (jpeg images) and I want to convert that into an MxN array so the final output would be an image made of all the input images from the array, put into the matrix from left to right, then from up to down. Suppose all input images are the same size, how do I do this in C++ using Opencv? Many thanks 回答1: This should do it: #include <opencv2/opencv.hpp> cv::Mat imageCollage( std::vector<cv::Mat> & array_of_images, int M, int N ) { // All images should be the same

Laplacian does not give desired output

断了今生、忘了曾经 提交于 2021-01-28 05:05:27
问题 Here is my code: int Factor=3,offset=0,k,l,p,q; IplImage * image = cvCreateImage(cvSize(img->width, img->height),img->depth, img->nChannels); cvCopy (img, image, 0); long double mean=0,nTemp=0,c,sum=0,n=0,s=0,d=0; int i=0,j=0,krow,kcol; kernel[0][0]=kernel[0][2]=kernel[2][0]=kernel[2][2]=0; kernel[0][1]=kernel[1][0]=kernel[1][2]=kernel[2][1]=1; kernel[1][1]=-4; uchar* temp_ptr=0 ; int rows=image->height,cols=image->width,row,col; //calculate the mean of image and deviation for ( row = 1; row

OpenCV - How to push back Mat in a queue?

僤鯓⒐⒋嵵緔 提交于 2021-01-28 04:55:36
问题 I am trying to put the frames of a video in a deque. This code does not work. Because the back and front of the queue are both the same as the current frame. deque<Mat> frameSeq; int main() { Mat frame; VideoCapture video("path to video"); int key = 0; while (key != 'q') { video >> frame; frameSeq.push_back(frame); imshow("front", frameSeq.front()); imshow("back", frameSeq.back()); key = cvWaitKey(1); } return 0; } But when I resize the frame: deque<Mat> frameSeq; int main() { Mat frame;

How to blur/ feather the edges of an object in an image using Opencv?

↘锁芯ラ 提交于 2021-01-28 04:25:17
问题 The objective is to blur the edges of a selected object in an image. I've done the steps to obtain the contours of the object by using the following code: image = cv2.imread('path of image') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(gray, 60, 255, cv2.THRESH_BINARY)[1] im, contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) I am also able to plot the contour using: cv2.drawContours(image, contours, -1, (0, 255, 0), 2)

Why is the color space of the CV::Mat image wrong (GBR instead of RGB or BGR)?

时光总嘲笑我的痴心妄想 提交于 2021-01-28 04:19:17
问题 I have a module in Python which sends an RGB to C++ and there its consumed. The image however, has wrong colorspace, regardless of what I do. That is I tried to convert it to RGB , assuming its still in BGR (although in python its deliberately converted into RGB by doing : return img[:,:,::-1] and visualize the image using matplotlib.) and vice versa, they look the same! This is shown below: Original image: This is the output of the image without any tampering This is the output when the I