예제 #1
0
 def handle_post():
     context = {'request': request}
     try:
         context['cloud_event'] = from_http(request.headers,
                                            request.get_data())
     except Exception:
         app.logger.warning('No CloudEvent available')
     return func.main(context)
예제 #2
0
파일: server.py 프로젝트: lance/parliament
    def handle_post():
        context = Context(request)
        try:
            context.cloud_event = from_http(request.headers,
                                            request.get_data())
        except Exception:
            app.logger.warning('No CloudEvent available')

        try:
            return func.main(context)
        except Exception as err:
            return f"Function threw {err}", 500
예제 #3
0
파일: Main.py 프로젝트: lei940324/spider
# -*- coding: utf-8 -*-
"""
Created on Thu Sep  3 00:01:08 2020

@author: Administrator
"""

from Config import keyword, time_start, time_end, clock, UserAgent, cookie, sleep, respider
from func import init_sql, get_time, get_url, main

# 初始化数据库
conn, cur = init_sql()

# 构建待爬取网址时间序列
timescope = get_time(time_start, time_end, clock)

# 构建待爬取网页队列
urlQueue = get_url(timescope, keyword, respider, conn, cur)

# 主程序运行
main(urlQueue, sleep, UserAgent, cookie, respider, conn, cur)
예제 #4
0
 def handle_get():
     context = {'request': request}
     return func.main(context)
예제 #5
0
파일: server.py 프로젝트: lance/parliament
 def handle_get():
     context = Context(request)
     return func.main(context)
예제 #6
0
def testthreshold(winName='tên của window', cam=1):
    capimg = cv2.VideoCapture(cam)
    if (capimg.isOpened() == False):
        print("Unable to read camera feed")
    if isinstance(cam, str):
        frameNum = int(capimg.get(cv2.CAP_PROP_FRAME_COUNT))
        x = np.array([np.arange(frameNum + 1)])
        y = np.zeros((1, frameNum + 1), np.uint8)

    def Trackchanged(x):
        pass

    cv2.namedWindow(winName)
    cv2.createTrackbar("THKersize", winName, 143, 401, Trackchanged)
    cv2.createTrackbar("C", winName, 48, 255, Trackchanged)
    cv2.createTrackbar('OpKerSize', winName, 3, 20, Trackchanged)
    cv2.createTrackbar('ErsKerSize', winName, 5, 20, Trackchanged)
    if isinstance(cam, str):
        cv2.createTrackbar('frame', winName, 8, frameNum, Trackchanged)
    while (True):
        THKersize = cv2.getTrackbarPos("THKersize", winName)
        C = cv2.getTrackbarPos("C", winName)
        OpKerSize = cv2.getTrackbarPos("OpKerSize", winName)
        ErsKerSize = cv2.getTrackbarPos("ErsKerSize", winName)
        if THKersize % 2 == 0 or OpKerSize % 2 == 0 or ErsKerSize % 2 == 0:
            plt.show
            plt.pause(0.0000001)
            pass
        else:
            if isinstance(cam, str):
                frameIndex = cv2.getTrackbarPos('frame', winName)
                capimg.set(cv2.CAP_PROP_POS_FRAMES, frameIndex - 1)
            ret, img = capimg.read()
            if ret == True:
                frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
                frame1 = frame[75:95, 220:420]

                opening_kernel = np.ones((OpKerSize, OpKerSize), np.uint8)

                #if blsize % 2 == 0:
                #pass
                #else:
                th = cv2.adaptiveThreshold(frame1, 255,
                                           cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                           cv2.THRESH_BINARY_INV, THKersize, C)
                #ret1, th = cv2.threshold(frame1, C, 255, cv2.THRESH_BINARY_INV)
                #ret2, th = cv2.threshold(frame1, C, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

                #th1 = cv2.adaptiveThreshold(frame1,255 , cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV, THKersize, C)
                opening = f.main('dilation', opening_kernel,
                                 f.main('erosion', opening_kernel, th))
                #opening = cv2.morphologyEx(th, cv2.MORPH_OPEN, opening_kernel)

                erosion_kernel = np.zeros((ErsKerSize, ErsKerSize), np.uint8)
                erosion_kernel[int((ErsKerSize - 1) / 2), :] = 1
                erosion = f.main('erosion', erosion_kernel, opening)
                #erosion = cv2.erode(opening, erosion_kernel, iterations=1)

                #edges = cv2.Canny(opening, 50, 200, apertureSize=3)
                edges = opening - erosion
                num1, count1 = np.unique(edges, return_counts=True)
                if num1[-1] == 255:
                    edge_num = count1[-1]
                else:
                    edge_num = 0
                print(edge_num)
                y[0, frameIndex] = edge_num
                plt.clf()
                plt.plot(x, y, "go")
                plt.grid()

                plt.show
                plt.pause(0.0000001)
                all = cv2.vconcat([th, opening, edges])

                #creat title for each image
                vtitle_size = int((480 - all.shape[0]) / 3)
                htitle_size = all.shape[1]

                th_title = np.zeros((vtitle_size, htitle_size, 1), np.uint8)
                th_title[:] = [220]
                cv2.putText(img=th_title,
                            text='Binary image',
                            fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                            fontScale=0.5,
                            color=0,
                            thickness=1,
                            lineType=cv2.LINE_AA,
                            org=(55, 75))

                op_title = np.zeros((vtitle_size, htitle_size, 1), np.uint8)
                op_title[:] = [220]
                cv2.putText(img=op_title,
                            text='After opening',
                            fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                            fontScale=0.5,
                            color=0,
                            thickness=1,
                            lineType=cv2.LINE_AA,
                            org=(55, 75))

                edge_title = np.zeros((vtitle_size, htitle_size, 1), np.uint8)
                edge_title[:] = [220]
                cv2.putText(img=edge_title,
                            text='Edge image',
                            fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                            fontScale=0.5,
                            color=0,
                            thickness=1,
                            lineType=cv2.LINE_AA,
                            org=(55, 75))
                if edge_num > 80:
                    cv2.rectangle(frame, (220, 75), (420, 95), (255, 255, 255),
                                  2)
                    #cv2.putText(img=frame, text='ERROR', fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.5, color=255,thickness=1,lineType=cv2.LINE_AA, org=(150, 90))
                else:
                    cv2.rectangle(frame, (220, 75), (420, 95), (0, 0, 0), 2)
                    #cv2.putText(img=frame, text='NORMAL', fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.5, color=0, thickness=1,lineType=cv2.LINE_AA, org=(150, 90))
                #all = cv2.vconcat([th_title, th, op_title, opening, edge_title, edges])
                all = cv2.hconcat([
                    frame,
                    cv2.vconcat(
                        [th_title, th, op_title, opening, edge_title, edges])
                ])

                cv2.imshow(winName, all)
                #edges = cv2.Canny(opening, 50, 200, apertureSize=3)
                #feat = np.sum(edges / 255)
                #print(feat)

                # Press Q on keyboard to stop recording
                if cv2.waitKey(1) & 0xFF == ord('q'):
                    break

            # Break the loop
            else:
                break

    # When everything done, release the video capture and video write objects
    capimg.release()
    # Closes all the frames
    cv2.destroyAllWindows()
예제 #7
0
import func

func.main('../../../raw_data/20171130/sun-20171130',
          '../../../raw_data/20171130/log', '../../../Data/data')
예제 #8
0
import numpy as np
from joblib import Parallel, delayed
import multiprocessing
from multiprocessing import Pool
from func import main, MC_pi, agg

if __name__ == "__main__":
    N = 1000000
    n_cpu = 5

    # with Multiprocessing
    print("results with multiprocessing")
    res2 = main(n_cpu, N, seeds=np.random.randint(100000, size=n_cpu))
    print("Aggregated estimate: %f" % (agg(res2, N)))
    print('___________')

    # with joblib
    print("results with joblib")
    res = Parallel(n_jobs=n_cpu)(delayed(MC_pi)(N) for _ in range(n_cpu))
    print(res)
    print("Aggregated estimate: %f" % (agg(res, N)))