Which is the better method of Histogram Equalisation? OpenCV/Python

I have written a program in Python that takes an image dataset of frontal views faces taken in lab settings (blank background etc.) and then classifies them using sklearn’s SVC. To create the feature vectors I use as the training and validation sets that I pass into SVC, the first step is to apply histogram equalisation to the images. In my testing, I have used both:

clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
clahe_image = clahe.apply(gray)

and

image = cv2.equalizeHist(gray)

Where gray is a grayscale image of a face. I have read about both of these methods in the documentation and online, but in practice, I have not seen much (if any) difference in performance.

Is there any reason I should pick one of these methods over the other?

Your browser tried to send a message without supplying a form boundary in the post

Trying to submit a post request to a really old website.

I am trying to post a payload similar to this (this is from google)

------WebKitFormBoundaryosJxc86zagk885w4
Content-Disposition: form-data; name="hashid"

+13334445555
------WebKitFormBoundaryosJxc86zagk885w4
Content-Disposition: form-data; name="reqUID"

ajpm
------WebKitFormBoundaryosJxc86zagk885w4
Content-Disposition: form-data; name="recipients"


------WebKitFormBoundaryosJxc86zagk885w4
Content-Disposition: form-data; name="file-name"


------WebKitFormBoundaryosJxc86zagk885w4
Content-Disposition: form-data; name="text"

too%20complicated
------WebKitFormBoundaryosJxc86zagk885w4--

with these headers (from inspect element):

Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.9
Connection:keep-alive
Content-Length:547
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryosJxc86zagk885w4
Host:127.0.0.1:333
Origin:http://127.0.0.1:333
Referer:http://127.0.0.1:333/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36
X-Requested-With:XMLHttpRequest

to http://127.0.0.1:333/sendMessage.srv.

I am using this simple python script to do it.

#!/usr/bin/env python3
import random
import requests
url = "http://127.0.0.1:333/sendMessage.srv/"
message = "hello"
number = "+13334445555"
# https://stackoverflow.com/questions/2267362/how-to-convert-an-integer-in-any-base-to-a-string
def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
    return ((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b]) 
reqId = baseN(round(random.random() * 1679616), 36) 
data = { 
        'hashid':number,
        'reqUID':reqId,
        'recipients':"",
        'file-name':"",
        'text':message,
}
r = requests.post(url, data=data)
print(r.status_code, r.reason)
print(r.text)
print("finished")

It gives me a 200 OK but it says Your browser tried to send a message without supplying a form boundary in the post.. What am I doing wrong?

date writing in csv file

I have written this code to write the date in a csv file (excel sheet) the code has no error but the date is not shown in the excel I need a read function but I don’t know how and where in the code to use it.

 date=["16.02.2018", "blah"]
    CSVreport = open('indata.csv', 'wb')
    wr = csv.writer(CSVreport)
    with open('indata.csv', 'w+') as CSVreport:
        wr = csv.writer(CSVreport)
        wr.writerow(date)
    CSVreport.close()

Can anyone help me?

Why do include paths in python2 and python3 differ?

While trying to make my scons based build system as platform independent as possible I was wondering about the following:

Why does python2 return the include path /usr/local/include/python2.7? This path does not contain Python.h and building fails if I rely on that path.

python2

Use sysconfig inside python2:

$ /usr/bin/python2
Python 2.7.13 (default, Nov 23 2017, 15:37:09) 
[GCC 6.3.0 20170406] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_path('include')
'/usr/local/include/python2.7'

Gives /usr/local/include/python2.7. This is an empty folder.

Call python2-config from shell:

$ /usr/bin/python2-config --includes
-I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7

This gives a different path. I was able to find Python.h in /usr/include/python2.7.

python3

Use sysconfig inside python3:

$ /usr/bin/python3
Python 3.5.3 (default, Nov 23 2017, 11:34:05) 
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_path('include')
'/usr/include/python3.5m'

Call python3-config from shell:

/usr/bin/python3-config --includes
-I/usr/include/python3.5m -I/usr/include/python3.5m

The resulting path /usr/include/python3.5m is the same for boath approaches. Python.h is located here.

anaconda

If I use anaconda python (2 or 3) the paths are also consistent (as with python3).

I already found some workarounds such as placing a softlink to usr/include in usr/local/include or just throwing away the local/ in the path, but both do not really look like a nice solution.

edit:

Currently the incorrect include path in python2 makes my build system not as platform independend as I would like. Adding an (optional) environment variable PYTHON_INCLUDE_PATH gives me the possibility to define the correct path, if python2 is used. But a solution where the correct path is always returned would help me a lot (either on python side or using scons-specific functionality).
As my build system is based on scons a

python eval error with converting string to dict

i am working with python and when i do eval on a string to get a dictionary it shows me the error “SyntaxError: invalid syntax”
the string is received over a socket connection and it contains a dictionary.
i need to get back the original dictionary

Exact error is below

File "<string>", line 1 
##here goes my long string received over socket
                                   ^
SyntaxError: invalid syntax

I have no idea whats going on in this.
I know i can use pickle or json to send data but thats not the req at the moment

Trouble importing python packages using PyCharm

I’ve been trying to install simple packages for python such as numpy and pandas, and while I am able to install the package manually from the command line using pip as soon as I try to import it PyCharm can’t find it. I have manually configured the path, with no luck.

PyCharm can also not find the packages I want to install itself and produces a connection timeout, this could be because I am working from a secure network.

Still pretty new to python and software dev in general, I apologise in advance if I’m being stupid, but no other similar threads are solving the issue.

I am operating on windows 7. The error I get is:

C:\Users\james.alexander\PycharmProjects\Test.py\venv1\Scripts\python.exe C:/Users/james.alexander/PycharmProjects/Test.py/testfile.py
Traceback (most recent call last):
  File "C:/Users/james.alexander/PycharmProjects/Test.py/testfile.py", line 1, in <module>
    import numpy
ModuleNotFoundError: No module named 'numpy'

Pyhon 3 Websockets, how to properly close socket

I have the following class for opening my websockets:

import os
import asyncio  
import websockets
import threading

class Server:

    def get_port(self):
        return os.getenv('WS_PORT', '9002')

    def get_host(self):
        return os.getenv('WS_HOST', 'localhost')

    def shutdown(self):
        self.loop.call_soon_threadsafe(self.loop.stop)

    def start(self):
        return websockets.serve(self.handler, self.get_host(), self.get_port())

Followed by some async handling methods for incoming messages. The loop function for getting the messages runs in its own thread, just for information.

I am able to terminate the program, however I was not able to close the sockets properly, cause it causes the following error on the restart of the script

OSError: [Errno 10048] error while attempting to bind on address ('127.0.0.1', 9002):

Since the port is already in use. Usually I would use some .close() function, however the websocket package does not provide such function, so I am wondering if I can get this done with the os package or the websocket package?

Pyhton 3.6.3: CSV Issue when assigning variable

UnboundLocalError: local variable 'csvreader' referenced before assignment line 6 in load_files
    csvreader = csvreader(f)
import csv

def load_files():
    try:
        with open("users.csv", "r", newline='') as f:
        csvreader = csvreader(f)
        csvreader.read(f)
        users = []
        for row in f:
            users.append(row)
except IOError:
    print("No Accounts Found!")
load_files()

Python how to use ImageGrab RGB values as a variable

Hi I am trying to write a code that will detect the colour of a pixel on the screen and then use that colour value as a variable to determine if a function will be run or not.

so far I have

from PIL import ImageGrab
px=ImageGrab.grab().load() #####screengrabs color
for y in range(0,100,10):
    for x in range(0,100,10):
        pixeltodetect=px[166,82]
if pixeltodetect == (range(140,160), range(5, 20), range(5, 20)):
    funstuff()

it will return an RGB value of (144, 8, 8) but it will still not run the function even though it is within the ranges listed here.