OpenCV

OpenCV image segmentation in C++ using Watershed

无人久伴 提交于 2021-02-18 08:11:14
问题 Hi i'm currently writing a basic C++ application using the OpenCV library to segment the subject of the image from its background. The application reads in an image file and uses the watershed algorithm to generate a mask based on data it finds around the edges and data it finds in the centre of the image. (To start I created an image object that has an overall value of -1. Then I created a border around an empty image which has a value of 1. Then I created a rectangle roughly in the centre

How to find the distance between two concentric contours, for different angles?

為{幸葍}努か 提交于 2021-02-18 08:02:48
问题 I have an image with two contours, where one contour is always 'inside' another. I want to find the distance between the two contours for 90 different angles (meaning, distance at every 4 degrees). How do I go about doing it? Here's an example image: Thank you! 回答1: In the following code, I have just given you the example for the vertical line, the rest can be obtained by rotating the line. Result looks like this, instead of drawing you can use the coordinates for distance calculation. import

Using a PNG image as mask for GrabCut

独自空忆成欢 提交于 2021-02-18 07:58:10
问题 I have a png image with green and red lines and transparent background, which I need to use is as a mask for executing GrabCut. But I get unexpected results. Here's my code: //find the mask Mat mask; mask.create( image.size(), CV_8UC1); mask.setTo(Scalar::all(GC_BGD)); Mat maskImg = imread("messi5.png"); for(int i=0; i<maskImg.cols; i++) for(int j=0; j<maskImg.rows; j++) { //if it's red, make it white if ((int)maskImg.at<cv::Vec3b>(j,i)[0]==0 && (int)maskImg.at<cv::Vec3b>(j,i)[1] == 0 && (int

Detecting start and end point of line in image (numpy array)

佐手、 提交于 2021-02-18 07:07:01
问题 I have an image like the following: What I would like is to get the coordinates of the start and end point of each segment. Actually what I thought was to consider the fact that each extreme point should have just one point belonging to the segment in its neighborhood, while all other point should have at least 2. Unfortunately the line does not have thickness equal to one pixel so this reasoning does not hold. 回答1: Here's a fairly simple way to do it: load the image and discard the

Detecting start and end point of line in image (numpy array)

守給你的承諾、 提交于 2021-02-18 07:04:13
问题 I have an image like the following: What I would like is to get the coordinates of the start and end point of each segment. Actually what I thought was to consider the fact that each extreme point should have just one point belonging to the segment in its neighborhood, while all other point should have at least 2. Unfortunately the line does not have thickness equal to one pixel so this reasoning does not hold. 回答1: Here's a fairly simple way to do it: load the image and discard the

How to use Opencv contours to describe line points in a unidirectional way

▼魔方 西西 提交于 2021-02-18 06:40:22
问题 I am using opencvs findContour to find the points to describe an image made up of lines (not polygons) as such: cv::findContours(src, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); . 回答1: If I understand correctly, the "cv2.connectedComponents" method gives what you are looking for. It assigns a label for each point in your image, the label is the same if points are connected. By doing this assignment there is no duplication happening. So, if your lines are one pixel wide

how to segment the connected area based on depth color in opencv

拜拜、爱过 提交于 2021-02-18 06:33:38
问题 I have a picture like , which i need to segment the picture into 8 blocks. I have tried this threshold method img_gray = cv2.imread(input_file,cv2.IMREAD_GRAYSCALE) ret,thresh = cv2.threshold(img_gray,254,255,cv2.THRESH_BINARY) = kernel = np.array(cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3), (-1, -1))) img_open = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel) cv2.imshow('abc',img_open) ret1,thresh1 = cv2.threshold(img_open,254,255,cv2.THRESH_BINARY_INV) # contours, hierarchy = cv2

Detect bad frames in OpenCV 2.4.9

一个人想着一个人 提交于 2021-02-18 06:29:05
问题 I know the title is a bit vague but I'm not sure how else to describe it. CentOS with ffmpeg + OpenCV 2.4.9. I'm working on a simple motion detection system which uses a stream from an IP camera (h264). Once in a while the stream hiccups and throws in a "bad frame" (see pic-bad.png link below). The problem is, these frames vary largely from the previous frames and causes a "motion" event to get triggered even though no actual motion occured. The pictures below will explain the problem. Good

Align two images in OpenCV

不问归期 提交于 2021-02-18 05:18:29
问题 I have two images (see below). These images represent the contours of a pair of cables and were captured using laser based 3D triangulation. The first image is captured with the left camera, while the second one with the right camera. As can be seen, these images are partially overlapping. The left part on the first image partly corresponds to the left part on the second image. The same holds for the right part. I want to merge these two images into one image so that the corresponding parts

C语言数据结构的套路

瘦欲@ 提交于 2021-02-17 20:40:27
搬运自我的CSDN https://blog.csdn.net/u013213111/article/details/93784522 跟着DSAA in C写代码,总结起来各种数据结构大概都是这个套路: 首先是定义: typedef struct XXXXX { //数据结构包含的元素 } XXX 然后分配空间, malloc(sizeof(XXX)) 对于用到数组来存储数据元素的,还要额外给数组分配空间,比如队列: Q->array = malloc(sizeof(int) * max); 最后用完之后一定要记得free! 这个套路用途广泛,比如想要把图片作为一个数据结构,首先可以这么定义: typedef struct ImgStruct { uint8_t *data; int width; int height; } Image; 然后导入图片(这里用了OpenCV,是C++,需要给函数包装一下才可以被C调用): Image *image_import(char *img_name) { Image *img; img = (Image *)malloc(sizeof(Image)); cv::Mat img_mat = cv::imread(img_name, cv::IMREAD_GRAYSCALE); img->width = img_mat.cols; img-