简体   繁体   English

获取_curses.error:curses function在windows-curses中返回NULL

[英]Getting _curses.error: curses function returned NULL in windows-curses

I checked other answers but I had no luck.我检查了其他答案,但没有运气。

So I'm doing a thing with open-cv and the terminal with windows-curses but I'm getting the _curses.error: curses function returned NULL error所以我正在使用 open-cv 和带有 windows-curses 的终端,但我得到了 _curses.error: curses function returned NULL 错误

I'm still a noobie with curses, therefore I have ZERO clue about why this happens我仍然是诅咒的菜鸟,因此我对为什么会发生这种情况的线索为零

Here's the code这是代码

from string import ascii_letters
import cv2 as cv
import numpy as np
import os
import curses as cs

basefolder = os.path.dirname(os.path.abspath(__file__)).replace(os.path.basename(__file__), '') + '\\'

def map_range(value, leftMin, leftMax, rightMin, rightMax):
    # Figure out how 'wide' each range is
    leftSpan = leftMax - leftMin
    rightSpan = rightMax - rightMin

    # Convert the left range into a 0-1 range (float)
    valueScaled = float(value - leftMin) / float(leftSpan)

    # Convert the 0-1 range into a value in the right range.
    return rightMin + (valueScaled * rightSpan)

def asciify(matrix):
    w, h = len(matrix[0]), len(matrix)
    
    asciis = '$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^`\'.'
    output = np.empty(shape=(h, w), dtype=str)

    for i in range(h):
        for j in range(w):
            asc = map_range(matrix[i, j], 255, 0, len(asciis)-1, 0)
            output[i, j] = asciis[int(asc)]





    return output


def main(stdscr):

    cs.initscr()

    img = cv.imread(basefolder + 'cat.jpg', 0)
    ascii_img = asciify(img)

    w, h = len(ascii_img[0]), len(ascii_img)

    win = cs.newwin(h, w, 0, 0)

    win.clear()
    
    for i in range(h):
        strg = []
        for j in range(w):
            strg.append(ascii_img[i, j])
        
        win.addstr(i, 0, ''.join(strg))


    win.refresh()
    stdscr.getch()

cs.wrapper(main)

On Windows I was able to get past the "_curses.error: curses function returned NULL error" by setting the environment variables for LINES and COLS.在 Windows 上,通过设置 LINES 和 COLS 的环境变量,我能够通过“_curses.error:curses function 返回 NULL 错误”。 In my case this was added to the runtime environment in pycharm under "Environment variables".在我的情况下,这是在“环境变量”下的 pycharm 中添加到运行时环境中的。 For example: LINES=40 COLS=80例如:LINES=40 COLS=80

If you are working in linux you can achieve the same result with:如果您在 linux 中工作,您可以通过以下方式获得相同的结果:

export LINES=40导出 LINES=40

export COLS=80出口 COLS=80

Set the values to something that works for your display - it is important that is scaled to fit the entire range that you are using so in your example it looks like you would need an area that handles the height and width of the matrix.将值设置为适合您的显示器的值 - 重要的是缩放以适合您使用的整个范围,因此在您的示例中看起来您需要一个处理矩阵高度和宽度的区域。

I have been having somewhat limited success with the windows-curses package.我在 Windows 诅咒 package 方面取得的成功有些有限。 I can get parts of it to work (newwin) and not others (newpad).我可以让它的一部分工作(newwin)而不是其他的(newpad)。 Works fine on Linux.在 Linux 上工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM