Author Archives: Robins

Modulenotfounderror: no module named ‘CV2’ – (version problem)

Ubuntu Running OpenCV project tip: ModuleNotFoundError: No Module Named ‘Cv2’
Haha, that was the problem when it was first installed. Just throw me up.
1. Reason: the versions are inconsistent
The problem is that when installing OpencV-Python, the detailed version number is appended, which makes it different from the Python environment. In addition, there will be other problems, I can’t remember exactly.
2. Solutions

    first use the instruction: PIP install opencv-python to execute once, if the .py file or so to see the next one; Just do not append the version number when installing OpencV-Python.

Error reporting of uncapped XML character


today when writing the JSP to such a mistake, Unescaped XML character,
solution is as follows:

select Editor – Inspections, and find the HTML on the right side of Malformed content of the script tag, uncheck the, click OK, and successfully solve the problem of error!

After IOS upgrade, the time control selected by the wheel will be invalid, uidatepicker

    2. If the previous style is used

 

datepicker.preferredDatePickerStyle = .wheels
    I don’t know if apple’s bug is wrong in both width and height

 

let datepicker = UIDatePicker(frame: CGRect(x: 0, y: 100, width: self.view.frame.width, height: 300))
 datepicker.preferredDatePickerStyle = .wheels  
 datepicker.backgroundColor = UIColor.yellow    
 datepicker.datePickerMode = .dateAndTime    
 self.view.addSubview(datepicker)


 
4. To fix this, set the frame after the datePickerMode and set it to normal
 

override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .white
        
      

Server (for example: HTTP) has a large number of time_ Solutions to wait

To understand TCP several state of the students, we should all know, TCP active disconnected side will appear TIME_WAIT state, TIME_WAIT state will keep the MSL 2 time, this is mainly used to prevent, take the initiative to open a party sent to the LAST lost a FIN ACK, lead to passive passive close one LAST – ACK timer timeout retransmission FIN, avoid the TCP state of chaos. However, in the case of high server concurrency, this default mechanism may cause the server to maintain a large amount of TIME_WAIT state, resulting in a large waste of resources, which may affect subsequent connection and request processing. To solve this phenomenon, we can modify the configuration of the server. Here we take the configuration of a Linux server on Aliyun as an example.
[root@izbp1dnvbin1s4fqqr8izfz ~]# cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
fs.file-max = 1000000
net.core.somaxconn = 2048
net.core.rmem_default = 16777216
net.core.wmem_default = 16777216
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_max_syn_backlog = 16384
net.core.netdev_max_backlog = 20000
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_max_tw_buckets = 40000
vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time=120
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce = 2
Net. Ipv4.com.lo. Arp_announce =2
net. Ipv4.com.conf.all. Arp_announce =2
net Net ipv4.tcp_fin_TIMEOUT (FIN timeout), net ipv4.tcp_TW_reuse (time_wait state socket reuse to allow socket to be used for a new TCP connection, default 0, Net ipv4.tcp_tw_recycle(fast recovery of time-wait sockets in TCP connections, default is 0, close), and then use the /sbin/ sysctL-p command to make the configuration work.

Visionox shows app development record

Vicino display APP plays pictures and videos in turn:
1. Develop the advertisement bar to load three pictures:



The three images will be displayed in turn in the form of banner ads.
When you click the image, you will exit the APP. When you press the image long, you will load the video.

Spring integrates JUnit configuration

2. In junit unit tests, executing
junit without a main method determines which methods in the current Test class have @test annotations
junit lets annotated methods execute
. Junit doesn’t matter if we’re using the spring framework
4. When the test method executes without an IOC container, a null pointer exception is raised even when the @Autowried annotation is written
Solution:
Spring integration junit configuration
1. 2. Replace the main method with the @runwith
3 provided by Spring with an annotation provided by junit. Runner told spring, spring and ioc creation is based on XML and annotation, and show the position of
annotation-based: @ ContextConfiguration (classes = SpringConfiguration. Class)
based on the configuration file: @ ContextConfiguration (locations = “classpath: bean. XML”)

Ubuntu18.04 installing Tomcat 8.5

Refer to the link
1. Download
and go to Apache Tomcat® official website to download
. Select the tar.gz version under Core
2. Move, unzip

mv apache-tomcat-8.5.60.tar.gz /opt/software
tar -zxvf /opt/software/apache-tomcat-6.0.41.tar.gz -C /opt/module/tomcat8.5.60 

3. Modify the configuration (1) to modify the startup script, add lines 67-66
/opt/module/tomcat8.5.60/bin/startup. Sh

(2) start in tomcat bin directory, run./startup. Sh, Start tomcat
./startup. Sh

(3) verify
browser enter localhost:8080, access successful

When IntelliJ idea is programmed, 1. Black thick line or black cursor appears; 2. The solution of carriage return unable to wrap. (practical recommendation method 2)

Intellij idea programming 1. Black thick lines or black cursor 2. A solution that cannot wrap a line by carriage return. (Practical Recommendation Method 2)

reason: it is usually caused by accidentally pressing insert. Some computers abbreviate insert, putting Del and Ins together, and Ins is the insert key.
Method 1. Click Intellij Idea on the upper left corner of the main interface, File> Settings> The diagram below * * * *
Put him on the Use block caret, and you can get back to your old self. ***

Method 2 (recommended) : Press and hold the Fn+ INSERT key to restore directly.
note: do not press Fn+insert if Use block caret is checked, otherwise the enter key will fail to wrap.
PS: restore the enter enter key newline function solution:
cancel Use block caret in the check box (default is no check, no change can be ignored), and then hold down Fn+insert key, so that the cursor and return will return to the original.

Invalidation of margin top property of nested box in CSS style box

When we write CSS styles, when two boxes are nested together, the top of the inside box is placed on the top of the outside box, as shown in the figure below:

At this time, if the properties like margin-top are set for the inner box, there will be no space between the top of the inner box and the outer box, but the outer box is pushed down, as if margin-top property is set for the outer box.
set margin-top property for the inner box, as shown in the figure below:

<style>
* {
    margin: 0;
    padding: 0;
}
.wrap {
    width: 200px;
    height: 200px;
    background-color: red;
}
.wrap .box {
    width: 100px;
    height: 100px;
    background-color: blue;
    margin-top: 50px;
}
</style>
<body>
    <div class="wrap">
        <div class="box"></div>
    </div>
</body>


so the simplest way is to add a property to the outer box :

overflow: hidden;

The results are as follows:

Android converts a view to bitmap + to handle the black edge of the view with rounded corners

Recently, the company has been working on a poster production function, which is to write a layout and plug in various data locally, and then save the whole layout as an image to the phone, so you need to turn a view into a bitmap.
Convert a View into a Bitmap

public static Bitmap createBitmapFromView(View view) {
      //If the ImageView is getting directly
        if (view instanceof ImageView) {
            Drawable drawable = ((ImageView) view).getDrawable();
            if (drawable instanceof BitmapDrawable) {
                return ((BitmapDrawable) drawable).getBitmap();
            }
        }
        view.clearFocus();
        Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
        if (bitmap != null) {
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
            canvas.setBitmap(null);
        }
        return bitmap;
}

The above method can be used to turn a view into a bitmap, which can meet the needs of most people
However, in my actual development, the layout had rounded corners, and all the pictures saved by this method were filled with black. After trying many methods, I finally solved my problem by drawing a background color with canvas. The code is as follows.
Handle the black edge of the rounded View

  public static Bitmap createBitmapFromView(View view) {
        if (view instanceof ImageView) {
            Drawable drawable = ((ImageView) view).getDrawable();
            if (drawable instanceof BitmapDrawable) {
                return ((BitmapDrawable) drawable).getBitmap();
            }
        }
        view.clearFocus();
        Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
        if (bitmap != null) {
            Canvas canvas = new Canvas(bitmap);
            canvas.drawColor(Color.WHITE);//Here you can change to other colors
            view.draw(canvas);
        }
        return bitmap;
    }

How to use Runtime.getRuntime().Exec()

1. Wrong way to use it

Runtime.getRuntime().exec("xxx");

2. Correct usage

//You need to specify parameter one: command location; parameter two: -c means execute the first parameter first; parameter three: your command.
Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","xxx"});

Such as:

try {
    Runtime.getRuntime().exec(new String[]{"/system/bin/sh","-c","reboot"});
}catch (Exception e) {
    e.printStackTrace();
}

Openmv identifies two-dimensional code, color recognition and serial communication

Openmv recognizes TWO-DIMENSIONAL code, color recognition and serial port communication
Objective Two-dimensional code recognition color recognition serial port communication complete code

purpose
1. Specify the content of the QR code: “XXX + XXX”, identify, return and send the corresponding serial number to the serial port; 2. Identify the color of materials in order according to the content of the two-dimensional code
3. Turn on the green light when standby, turn on the blue light when performing the action, and turn off the LED when the action is over.
Two-dimensional code recognition

while(True):
    img = sensor.snapshot()
    img.lens_corr(1.8)
    for code in img.find_qrcodes():
        output_str="%s" % code.payload()
		#output_str is QR code content

Attached (Forage TWO-DIMENSIONAL code generator)
Color identification

#Color Threshold
green_threshold   = (73, 96, -79, -22, -128, 127)
red_threshold   = (41, 61, 42, 127, -128, 127)
blue_threshold   = (22, 67, 9, 127, -128, -54)

blobs = img.find_blobs([green_threshold,red_threshold,blue_threshold],x_stride=25,y_stride=50,area_threshold=1000)
for b in blobs:
	img.draw_rectangle(b[0:4]) # rect
    #Mark the target color area with a rectangle
    img.draw_cross(b[5], b[6]) # cx, cy
    # draw a cross in the center of the target color area
    print(b[8]) # b[8] is the color code, red=2,green=1,blue=4

A serial port communication

if uart.any():# determine if data is received
	getrx = uart.readline()# read data
	uart.write('abc')#Send data

The complete code

import sensor, image, time, pyb
import ujson
from pyb import UART

green_threshold   = (73, 96, -79, -22, -128, 127)
#(0, 100, -128, -25, -128, 127)
red_threshold   = (41, 61, 42, 127, -128, 127)
#(41, 61, 42, 127, -128, 127)
blue_threshold   = (22, 67, 9, 127, -128, -54)
#(15, 100, -128, 127, -128, -41)
#red=2,green=1,blue=4
getrx = 0
getcmd = 0
renum = 0
colornum = 0
ptrposition = 0
sensor.reset()# Initialize the camera
sensor.set_pixformat(sensor.RGB565)# formatted as RGB565.
sensor.set_framesize(sensor.QQVGA) # Use QQVGA for faster speed
sensor.skip_frames(time = 2000) # Skip 2000s, make the new settings take effect, and adjust the white balance automatically
sensor.set_auto_gain(False) # Turn off auto gain. The default is on, in the color recognition, make sure to turn off the white balance.
sensor.set_auto_whitebal(False)
# Turn off white balance. White balance is on by default. In color recognition, be sure to turn off white balance.
clock = time.clock() # Track frame rate
led = pyb.LED(1) # Red LED = 1, Green LED = 1, Blue LED = 2, IR LEDs = 4.
uart = UART(3, 115200, timeout_char = 1000)
led.on()

def Rec_NUM1(lista):
    if (lista[0]=='1' and lista[1]=='2' and lista[2]=='3'):
        return 1
    elif (lista[0]=='1' and lista[1]=='3' and lista[2]=='2'):
        return 2
    elif (lista[0]=='2' and lista[1]=='1' and lista[2]=='3'):
        return 3
    elif (lista[0]=='2' and lista[1]=='3' and lista[2]=='1'):
        return 4
    elif (lista[0]=='3' and lista[1]=='1' and lista[2]=='2'):
        return 5
    elif (lista[0]=='3' and lista[1]=='2' and lista[2]=='1'):
        return 6

def Rec_NUM2(lista):
    if (lista[4]=='1' and lista[5]=='2' and lista[6]=='3'):
        return 1
    elif (lista[4]=='1' and lista[5]=='3' and lista[6]=='2'):
        return 2
    elif (lista[4]=='2' and lista[5]=='1' and lista[6]=='3'):
        return 3
    elif (lista[4]=='2' and lista[5]=='3' and lista[6]=='1'):
        return 4
    elif (lista[4]=='3' and lista[5]=='1' and lista[6]=='2'):
        return 5
    elif (lista[4]=='3' and lista[5]=='2' and lista[6]=='1'):
        return 6

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    if uart.any():
        led.off()
        getrx = uart.readline()
        time.sleep(150)     #Time delay 150ms
        led = pyb.LED(2)
        led.on()
        getcmd = int(getrx)
        print(getcmd)
      #  print(img.find_qrcodes())
    img = sensor.snapshot()# 从The light-sensitive chip acquires an image
    img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
    blobs = img.find_blobs([green_threshold,red_threshold,blue_threshold],x_stride=25,y_stride=50,area_threshold=1000)
    if(getcmd==2):
        for code in img.find_qrcodes():
            output_str="%s" % code.payload() #Method 1
            renum = int(Rec_NUM1(output_str)*10 + Rec_NUM2(output_str))
            uart.write(ujson.dumps(renum))
            getcmd = 0
            led.off()
    if blobs and getcmd==3:
        for b in blobs:
            # Draw a rect around the blob.
            img.draw_rectangle(b[0:4]) # rect
            #Mark the target color area with a rectangle
            img.draw_cross(b[5], b[6]) # cx, cy
            # Draw a cross in the center of the target color area
            #print(b[5], b[6], b[8])
            #uart.write(ujson.dumps(b[8]))
            #transfer color serial number to race serial number
            if b[8]==1:
                colornum=2
            elif b[8]==2:
                colornum=1
            elif b[8]==4:
                colornum=3
            print('colornum=',colornum,'output_str[ptrposition]=',output_str[ptrposition])
            #If the task code corresponds to
            if (int(output_str[ptrposition]) == colornum):
                uart.write('t')
                ptrposition+=1
                if ptrposition==4:
                    ptrposition+=1
                getcmd=0