Project

General

Profile

Feature #471 » mainDisplay_v0.2.py

Anonymous, 01/04/2022 07:53 PM

 
1
# Vaibhav GUPTA - Made the skeleton python code for displaying the main image with the projector
2
# ˅˅˅˅˅
3
    from configure_reader import ConfigureReader
4
    from image_correction import image_Correction
5
    import cv2
6
    import socket
7

    
8
    cR = ConfigureReader()
9
    iC = image_Correction()
10

    
11
    # Display the corrected image of one side and send the other side to TCP
12
    class MainDisplay(object):
13
        IP_Address
14
        frame = 0
15
        Port
16

    
17
        # Constructor
18
        def __init__(self):
19
            pass
20

    
21
        def displayImage():
22
            gamma = float(cR.getGamma())
23

    
24
            while True:
25
                self.frame += 1
26

    
27
                # Get correct image data of RGBA
28
                outputImages = iC.alphaBlending(gamma)
29

    
30
                if(CR.getProjectorSide() == "left"):
31
                    if textcounter < texttimeout:
32
                        outtext = outputImages[0].copy()
33
                        cv2.imshow("outputL.png", cv2.putText(outtext, "Current Gamma - " + str(round(gamma,2)) + ", Frame:" + str(self.frame)+" Save with (Q)", org = (400, 700), fontFace = cv2.FONT_HERSHEY_COMPLEX_SMALL, fontScale = 2, color = (0,0,255)))
34
                    else:
35
                        cv2.imshow("outputL.png", outputImages[0])
36
                elif(CR.getProjectorSide() == "right"):
37
                    if textcounter < texttimeout:
38
                        outtext = outputImages[1].copy()
39
                        cv2.imshow("outputR.png", cv2.putText(outtext, "Current Gamma - " + str(round(gamma,2)) + ", Frame:" + str(self.frame)+" Save with (Q)", org = (400, 700), fontFace = cv2.FONT_HERSHEY_COMPLEX_SMALL, fontScale = 2, color = (0,0,255)))
40
                    else:
41
                        cv2.imshow("outputR.png", outputImages[1])
42

    
43
                key = cv2.waitKey(1)
44
                if key == 27:
45
                    break
46
                if key == ord('q'):
47
                    # Saving the current gamma settings to configuration file
48
                    cR.setGammaSetting(str(round(gamma,2)))
49
                else:
50
                    # Gamma adjust to create gamma mask
51
                    if key == ord('w') or key == ord('s') or key == ord('e') or key == ord('d') or self.frame == 1:
52

    
53
                        textCount = 0
54
                        if key == ord('w'):
55
                            gamma += 0.1
56

    
57
                        elif key == ord('s'):
58
                            if gamma - 0.1 > 0:
59
                                gamma -= 0.1
60
                        elif key == ord('e'):
61
                            gamma += 0.01
62

    
63
                        elif key == ord('d'):
64
                            if gamma - 0.1 > 0:
65
                                gamma -= 0.01
66

    
67
                        outputImages = iC.alphaBlending(gamma)
68
            
69
                        # Sending the image to the TCP 
70
                        self.sendImage()
71

    
72
                textCount += 1
73

    
74
            cv2.destroyAllWindows()
75

    
76
    mainStich().displayImage()
77
# ˄˄˄˄˄
    (1-1/1)