Sida 2 av 2

Re: 1 klicks program för att fota från wencam + corp + skala

Postat: 1 december 2018, 06:12:56
av lgrfbs
Tack, nu fungerade allt.
:tumupp: :tumupp: :tumupp: :tumupp: :tumupp: av 5

Re: 1 klicks program för att fota från wencam [Avslutat]

Postat: 1 december 2018, 07:33:09
av lgrfbs
Så här blev koden efter jag testat den:

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!"
Grymt mycket tack till Knappas för denna kod!

Re: 1 klicks program för att fota från wencam [Avslutat]

Postat: 1 december 2018, 09:18:04
av Knappas
Ingen orsak, kul att det fungerade :tumupp:

Och ett omnämnande också :)

Re: 1 klicks program för att fota från wencam [Avslutat]

Postat: 1 december 2018, 16:21:31
av lgrfbs
Så här blev det på första körning i rätta datorn (labbat på min laptop innan).
py-Rcam 1 run 2018-12-01a.png
Får peta på lite positioner, men så när på en gång är ju rätt bra.