Re: 1 klicks program för att fota från wencam + corp + skala
Postat: 1 december 2018, 06:12:56
Tack, nu fungerade allt.
av 5





Svenskt forum för elektroniksnack.
https://elektronikforumet.com/forum/
Kod: Markera allt
#import numpy as np
import cv2
import time
import os
# Create a camera object-
camera_port = 0
camera = cv2.VideoCapture(camera_port)
# Set resolution of the image you want to capture, the capured image is as close as possible
# what the hardware can deliver.
width, height = 1280, 720
camera.set(cv2.CAP_PROP_FRAME_WIDTH, width)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
print "Model railrod stock camera version 1.0 by Knappas on Svenska ElektronikForumet "
print "made to lgrfbs on Svenska ElektronikForumet will be used on GMJ test track 2018"
print "------------------------------------------------------------------------------- "
print "Press [Space] to take a photo."
print "Press Q for quit/exit this program."
print "Photo folder:"+os.getcwd()
print "------------------------------------------------------------------------------- "
print " "
while(True):
# Capture frame-by-frame
ret, img = camera.read()
# Crop the image
#cx, cy, cw, ch = 100, 190, 1080, 340
Image_propositions=2
cx, cy, cw, ch = 100, 190, (230*Image_propositions), (80*Image_propositions)
cropped_img = img[cy:cy+ch, cx:cx+cw]
# Resize the cropped image, but you can use img instead if you want to resize the original.
rw, rh = 230, 80
resized_img = cv2.resize(cropped_img, (rw, rh))
# Display the full image with the cropped area marked with a green rectangle.
img = cv2.rectangle(img, (cx, cy), (cx + cw, cy + ch), (0,255,0), 2)
cv2.imshow('Video', img)
# Check for pressed keys
# <Space> = Take snapshoot
# q or ESC quits
key = cv2.waitKey(1) & 0xFF
if key == ord('q') or key == 27:
break
if key == ord(' '):
# Create a filename and save the cropped and resized image
filename = time.strftime("Picture%y%m%d %H%M%S.jpg", time.localtime())
print filename + " Taken!"
cv2.imwrite(filename, resized_img)
# When everything done, release the capture
camera.release()
cv2.destroyAllWindows()
print "Bye!"