Esempio n. 1
0
    def run(self):
        started = time.time()
        while True:

            currentframe = cv.QueryFrame(self.capture)
            instant = time.time()  #Get timestamp o the frame

            self.processImage(currentframe)  #Process the image

            if not self.isRecording:
                if self.somethingHasMoved():
                    self.trigger_time = instant  #Update the trigger_time
                    if instant > started + 10:  #Wait 5 second after the webcam start for luminosity adjusting etc..
                        print "Something is moving !"
                        if self.doRecord:  #set isRecording=True only if we record a video
                            self.isRecording = True
                cv.DrawContours(currentframe, self.currentcontours,
                                (0, 0, 255), (0, 255, 0), 1, 2, cv.CV_FILLED)
            else:
                if instant >= self.trigger_time + 10:  #Record during 10 seconds
                    print "Stop recording"
                    self.isRecording = False
                else:
                    cv.PutText(currentframe,
                               datetime.now().strftime("%b %d, %H:%M:%S"),
                               (25, 30), self.font, 0)  #Put date on the frame
                    cv.WriteFrame(self.writer, currentframe)  #Write the frame

            if self.show:
                cv.ShowImage("Image", currentframe)

            c = cv.WaitKey(1) % 0x100
            if c == 27 or c == 10:  #Break if user enters 'Esc'.
                break
Esempio n. 2
0
    def run(self):
        started = time.time()
        while True:

            curframe = cv.QueryFrame(self.capture)
            instant = time.time()  #Get timestamp o the frame

            self.processImage(curframe)  #Process the image

            if not self.isRecording:
                if self.somethingHasMoved():
                    self.trigger_time = instant  #Update the trigger_time
                    if instant > started + 5:  #Wait 5 second after the webcam start for luminosity adjusting etc..
                        print("Something is moving !")
                        if self.doRecord:  #set isRecording=True only if we record a video
                            self.isRecording = True
            else:
                if instant >= self.trigger_time + 10:  #Record during 10 seconds
                    print("Stop recording")
                    self.isRecording = False
                else:
                    cv.PutText(curframe,
                               datetime.now().strftime("%b %d, %H:%M:%S"),
                               (25, 30), self.font, 0)  #Put date on the frame
                    cv.WriteFrame(self.writer, curframe)  #Write the frame

            if self.show:
                cv.ShowImage("Image", curframe)
                cv.ShowImage("Res", self.res)

            cv.Copy(self.frame2gray, self.frame1gray)
            c = cv.WaitKey(1)
            if c == 27 or c == 1048603:  #Break if user enters 'Esc'.
                break
Esempio n. 3
0
print(list_length)

# 查看数组维度,shape验证
print(pixel_list_np_1.ndim)
print(pixel_list_np_1.shape)
# print( pixel_list_np_1)

print(pixel_list_np_2.ndim)
print(pixel_list_np_2.shape)
# print( pixel_list_np_2)

# print( pixel_sum)

# 画条形图
plt.figure(1)
width = 1
for i in range(len(pixel_sum)):
    plt.figure(1)
    plt.bar(i, pixel_sum[i], width)
plt.xlabel("X")
plt.ylabel("pixel_sum")
plt.show()

# 按ESC退出,按s保存图片
k = cv.waitKey(100)
if k == 27:  # wait for ESC key to exit
    cv.DestroyAllWindows()
elif k == ord('s'):  # wait for 's' key to save and exit
    cv.WriteFrame('copy_test.png', lwpImg)
    cv.DestroyAllWindows()