how to remove salt and pepper noise from images using python?

I have tried to implement the following algorithm but the resulting image looks the same. Step 1 : Read Noisy Image. Step 2 : Select 2D window of size 3x3 with centre element as processing pixel. Assume that the pixel being processed is P ij . Step 3 : If P ij is an uncorrupted pixel (that is, 0< P ij <255), then its value is left unchanged. Step 4 : If P ij = 0 or P ij = 255, then

如何使用python从图像中去除盐和胡椒的噪音?

我试图实现以下算法,但生成的图像看起来相同。 第1步 :读取噪声图像。 步骤2 :选择以中心元素作为处理像素的尺寸为3×3的2D窗口。 假设正在处理的像素是P ij。 步骤3 :如果P ij是未损坏的像素(即,0 <P ij <255),则其值保持不变。 步骤4 :如果P ij = 0或P ij = 255,则P ij是损坏的像素。 步骤5 :如果所选窗口中的3/4或更多像素有噪声,则将窗口大小增加至5x5。 步骤6:如果所选窗口中的所有元素均为0

Horizon Line Detection via Canny and Hough

I am trying to detect horizon line in python. In order to achieve my goal, firstly I used canny edge detection algorithm. sea.jpg import cv2 import numpy as np gray = cv2.imread('images/sea.jpg') edges = cv2.Canny(gray,50,150,apertureSize = 3) After edge detection, I applied hough transform to image. minLineLength=100 lines = cv2.HoughLinesP(image=edges,rho=10,theta=np.pi/180, threshold=1,

通过Canny和Hough的地平线检测

我正在尝试在python中检测地平线。 为了实现我的目标,首先我使用了canny边缘检测算法。 sea.jpg import cv2 import numpy as np gray = cv2.imread('images/sea.jpg') edges = cv2.Canny(gray,50,150,apertureSize = 3) 在边缘检测之后,我将hough变换应用于图像。 minLineLength=100 lines = cv2.HoughLinesP(image=edges,rho=10,theta=np.pi/180, threshold=1,lines=np.array([]), minLineLength=minLineLength,maxLine

Detecting a can or bottle in opencv

I am new to OpenCV and have a few questions. I need to detect a bottle or a can based on their shape. For this I am using a raspberry pi board and pi camera. The background is always black and does not change. I have tried many possible solutions to this problem but could not get satisfactory results. The things I have tried include edge detection, morphological transformations, matchShapes(

在opencv中检测罐头或瓶子

我是OpenCV的新手,并且有几个问题。 我需要根据它们的形状来检测瓶子或罐子。 为此我使用覆盆子pi板和pi相机。 背景总是黑色,不会改变。 我已经尝试了很多可能的解决方案来解决这个问题,但是得不到满意的结果 我尝试过的东西包括边缘检测,形态转换,matchShapes(),matchTemplate()。 请让我知道我是否能够以最高的准确性有效地完成这项任务。 示例图像: 我想出了一个可能有用的方法! 如果你对罐头有更多的

Python, OpenCV: classify gender using ORB features and KNN

Task: Classify images of human faces as female or male. Training images with labels are available, obtain the test image from webcam. Using: Python 2.7, OpenCV 2.4.4 I am using ORB to extract features from a grayscale image which I hope to use for training a K-Nearest Neighbor classifier. Each training image is of a different person so the number of keypoints and descriptors for each image

Python,OpenCV:使用ORB特性和KNN对性别进行分类

任务:将人脸图像分类为女性或男性。 使用标签培训图像可用,从网络摄像头获取测试图像。 使用: Python 2.7,OpenCV 2.4.4 我正在使用ORB从灰度图像中提取特征,我希望用它来训练K-最近邻分类器。 每个训练图像都是不同的人,因此每个图像的关键点和描述符的数量明显不同。 我的问题是,我无法理解KNN和ORB的OpenCV文档。 我还看过关于ORB,KNN和FLANN的其他SO问题,但他们没有太多帮助。 ORB给出的描述符的性质究竟

Python import Dynamic or Static License restriction

I have Python application which needs to be released commercially ( Closed Source), We are using some modules which are licensed GPL. If I understood correctly then GPL put restrictions that I can not link GPL code statically if I want to release it under closed source. Some other questions for dynamic import suggest using __import__ but I think that will work the same way, atleast when we wi

Python导入动态或静态许可限制

我有Python应用程序需要商业发布(封闭源代码),我们正在使用一些许可GPL模块。 如果我理解正确的话,那么GPL就会限制我不能静态链接GPL代码,如果我想在封闭源代码下释放它的话。 动态导入的其他一些问题提示使用__import__但我认为这将以同样的方式工作,至少当我们将生成二进制文件时。 你需要与一位律师(或几个)交谈,但是法学家基本上是正确的; 如果您的代码包含GPL代码,则您必须根据GPL条款发布源代码。 如果

Need performance on postGIS with GeoDjango

This is the first time I'm using GeoDjango with postGIS. After installation and some tests with everything running fine I am concerned about query performance when table rows will grow. I'm saving in a geometry point longitudes and latitudes that I get from Google geocoding (WGS84, or SRID 4326). My problem is that distance operations are very common in my application. I often need t

使用GeoDjango需要postGIS性能

这是我第一次在PostGIS中使用GeoDjango。 在安装和一切正常运行的测试之后,我担心表格行增长时的查询性能。 我正在保存从Google地理编码(WGS84或SRID 4326)获得的几何点经度和纬度。 我的问题是距离操作在我的应用程序中很常见。 我经常需要靠近地标附近的景点。 几何数学是非常复杂的,所以即使我有一个空间索引,未来可能需要很长的时间,在附近地区有超过1000个点。 那么有什么方法可以投影这个几何类型来更快地进

Consume multiple messages at a time

I am using an external service (Service) to process some particular type of objects. The Service works faster if I send objects in batches of 10. My current architecture is as follows. A producer broadcasts objects one-by-one, and a bunch of consumers pull them (one-by-one) from a queue and send them to The Service. This is obviously suboptimal. I don't want to modify producer code as it

一次消费多条消息

我正在使用外部服务(服务)来处理某些特定类型的对象。 如果我以10个批次发送对象,则该服务工作得更快。我当前的体系结构如下所示。 生产者一个接一个地播放对象,一群消费者从队列中一个接一个地将它们拉出来并发送给服务。 这显然不是最理想的。 我不想修改生产者代码,因为它可以在不同的情况下使用。 我可以修改消费者代码,但只能增加复杂性的代价。 我也知道prefetch_count选项,但我认为它只适用于网络级别 - 客

running command in background

I am using python subprocess module to run some command and store its output in background. The command is deployed on my machine. Now whenever i run the command from shell prompt it works fine. But when I try to run the same command using subprocess module it gives following error The command to be executed is vxswadm listswitch all process = subprocess.Popen('vxswadm listswitch all > t

在后台运行命令

我正在使用python subprocess模块​​来运行一些命令并将其输出存储在后台。 该命令部署在我的机器上。 现在,每当我从shell提示符运行命令,它工作正常。 但是当我尝试使用子进程模块运行相同的命令时,它会产生以下错误 要执行的命令是vxswadm listswitch all process = subprocess.Popen('vxswadm listswitch all > tmp.txt &',shell=True) >>> Traceback (most recent call last): File "/

Get parent user after sudo with Python

I would like to get the parent user after a sudo command in Python For example, from the shell I can do: # Shows root; *undesired* output $ sudo whoami root # Shows parent user sjcipher, desired output $ sudo who am i sjcipher How do I do this in Python without using an external program? who am i gets it's information from utmp(5) ; with Python you can access with information with pyutm

在使用Python完成sudo之后获取父级用户

我希望在Python中使用sudo命令后获得父级用户例如,在shell中,我可以执行以下操作: # Shows root; *undesired* output $ sudo whoami root # Shows parent user sjcipher, desired output $ sudo who am i sjcipher 如何在不使用外部程序的情况下在Python中执行此操作? who am i从utmp(5)得到它的信息; 用Python你可以用pyutmp访问信息; 这里有一个例子,改编自pyutmp主页: #!/usr/bin/env python2 from pyutmp imp

How to determine what user and group a Python script is running as?

I have a CGI script that is getting an "IOError: [Errno 13] Permission denied" error in the stack trace in the web server's error log. As part of debugging this problem, I'd like to add a little bit of code to the script to print the user and (especially) group that the script is running as, into the error log (presumably STDERR). I know I can just print the values to sys.st

如何确定Python脚本运行的用户和组?

我有一个CGI脚本,它在Web服务器错误日志中的堆栈跟踪中出现“IOError:[Errno 13] Permission denied”错误。 作为调试此问题的一部分,我想向脚本添加一些代码,以便将脚本正在运行的用户和(尤其是)组打印到错误日志(可能是STDERR)中。 我知道我可以将值打印到sys.stderr,但是如何找出脚本正在运行的用户和组? (我对这个组特别感兴趣,所以$ USER环境变量不会帮助; CGI脚本的setgid位已设置,因此它应该作为组“list