image-processing

OpenCV warpAffine and inverse warpAffine inconsistence

旧城冷巷雨未停 提交于 2020-08-06 02:05:09
问题 I'm using the OpenCV warpAffine function to do some image processing. The weird thing is that I found after applying a warpAffine and then an inverse warpAffine. The processed image is inconsistent with the original image, where there is one-pixel border padding at the bottom. img_path = '140028_199844.jpg' img = cv2.imread(img_path,cv2.IMREAD_COLOR) plt.imshow(img[:,:,::-1]) h,w,_=img.shape # h=220 w=173 src = np.array([[ 86., 109.5], [ 86. , 0. ], [-23.5, 0. ]]) dst = np.array([[192., 192.]

OpenCV warpAffine and inverse warpAffine inconsistence

扶醉桌前 提交于 2020-08-06 02:03:51
问题 I'm using the OpenCV warpAffine function to do some image processing. The weird thing is that I found after applying a warpAffine and then an inverse warpAffine. The processed image is inconsistent with the original image, where there is one-pixel border padding at the bottom. img_path = '140028_199844.jpg' img = cv2.imread(img_path,cv2.IMREAD_COLOR) plt.imshow(img[:,:,::-1]) h,w,_=img.shape # h=220 w=173 src = np.array([[ 86., 109.5], [ 86. , 0. ], [-23.5, 0. ]]) dst = np.array([[192., 192.]

How to map x,y pixel to world cordinates

末鹿安然 提交于 2020-08-05 11:47:11
问题 In my project I am calculating x,y in pixel and Z the distance from the camera in mm. So I want to make use of the depth and calculate the x,y,z. Can any one tell me how I can do that? I have the following information: x,y pixel obtained from the image Distance from the camera and the object distance from camera and object keep varying, since am making image from different distances 回答1: If you have x,y in image coordinates, a camera matrix, and z in world coordinates then you need to put

How to detect the horizontal and vertical lines of a table and eliminate the noise?

风流意气都作罢 提交于 2020-08-05 06:00:09
问题 I am trying to get the horizontal and vertical lines of the table in an image in order to extract the texts in cells. Here's a picture I use: I use the code below to extract the vertical and horizontal lines: img = cv2.imread(img_for_box_extraction_path, 0) # Read the image (thresh, img_bin) = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU) # Thresholding the image img_bin = 255-img_bin # Invert the image cv2.imwrite("Image_bin_2.jpg",img_bin) # Defining a kernel length

How to detect a rotated page in a PDF document in Python?

核能气质少年 提交于 2020-08-05 04:17:21
问题 Given a PDF document with multiple pages, how to check if a given page is rotated (-90, 90 or 180º)? Preferable using Python (pdfminer, pyPDF) ... UPDATE: The pages are scanned, and most of the page is composed by text. 回答1: I used simply /Rotate attribute of the page in PyPDF2 : pdf = PyPDF2.PdfFileReader(open('example.pdf', 'rb')) orientation = pdf.getPage(pagenumber).get('/Rotate') it can be 0 , 90 , 180 , 270 or None 来源: https://stackoverflow.com/questions/34515674/how-to-detect-a-rotated

How can I read an image from an Internet URL in Python cv2, scikit image and mahotas?

生来就可爱ヽ(ⅴ<●) 提交于 2020-08-02 05:39:25
问题 How can I read an image from an Internet URL in Python cv2? This Stack Overflow answer, import cv2.cv as cv import urllib2 from cStringIO import StringIO import PIL.Image as pil url="some_url" img_file = urllib2.urlopen(url) im = StringIO(img_file.read()) is not good because Python reported to me: TypeError: object.__new__(cStringIO.StringI) is not safe, use cStringIO.StringI.__new__ 回答1: Since a cv2 image is not a string (save a Unicode one, yucc), but a NumPy array, - use cv2 and NumPy to

Finding each centroid of multiple connected objects

和自甴很熟 提交于 2020-07-23 06:45:16
问题 I am SUPER new to python coding and would like some help. I was able to segment each cell outline within a biological tissue (super cool!) and now I am trying to find the centroid of each cell within a tissue using this: I am using this code: img = cv2.imread('/Users/kate/Desktop/SegmenterTest/SegmentedCells/Seg1.png') image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(image, 60, 255, cv2.THRESH_BINARY)[1] cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN

Larger than expected file sizes when saving a TIFF with OpenCV

。_饼干妹妹 提交于 2020-07-23 06:33:29
问题 I am creating a python program to load a .tiff image, crop out a selection from the image, and save the selection as a tiff. The dataset images are large, exceeding 1GB. I can successfully crop out what I need and save as a tiff, but the new image file sizes are much larger than what I expect and need. Opening I am using tifffile to open the image as a numpy array. OpenCV and PIL were not able to open the files due to size. I tried using OpenSlide as well, but encountered other problems down

Larger than expected file sizes when saving a TIFF with OpenCV

醉酒当歌 提交于 2020-07-23 06:31:28
问题 I am creating a python program to load a .tiff image, crop out a selection from the image, and save the selection as a tiff. The dataset images are large, exceeding 1GB. I can successfully crop out what I need and save as a tiff, but the new image file sizes are much larger than what I expect and need. Opening I am using tifffile to open the image as a numpy array. OpenCV and PIL were not able to open the files due to size. I tried using OpenSlide as well, but encountered other problems down

How to pixelate a binary (P6) PPM file

*爱你&永不变心* 提交于 2020-07-22 21:40:32
问题 I am struggling to pixelate an image which is made up of RGB values stored in a binary (P6) PPM file. The steps to pixelate the image are as follows: Read in the binary data and store it in a 1-dimensional array Iterate through the data stored in this array, in cells of size 'c' (row x columns). This variable 'c' can be changed by the user, but for this program it's currently set to int c = 4; meaning it iterates through pixel data in block dimensions of 4 x 4 Now find the average colour