打开CV - Python RGB到GRAY转换器(Open CV - Python RGB to GRAY convertor)
我想将这个RGB编码为灰度转换器而没有任何内置的Open-CV功能。 这就是我的代码的样子
import cv2 , numpy def GrayConvertor(img): rows , cols , layers = img.shape matrix = numpy.zeros((rows , cols)) for i in range(rows): for j in range(cols): val = 0.114 * (img[i][j][0]) + 0.587 * (img[i][j][1]) + 0.299 * (img[i][j][2]) fraction = val - int(val) if fraction >= 0.5: matrix[i][j] = (int(val) + 1) else: matrix[i][j] = int(val) cv2.imshow("gray" , matrix) cv2.waitKey(0)
然而它显示了一个空白图像,任何想法?
I wanted to code this RGB to grayscale convertor without any inbuilt Open-CV function. This is how my code looks like
import cv2 , numpy def GrayConvertor(img): rows , cols , layers = img.shape matrix = numpy.zeros((rows , cols)) for i in range(rows): for j in range(cols): val = 0.114 * (img[i][j][0]) + 0.587 * (img[i][j][1]) + 0.299 * (img[i][j][2]) fraction = val - int(val) if fraction >= 0.5: matrix[i][j] = (int(val) + 1) else: matrix[i][j] = int(val) cv2.imshow("gray" , matrix) cv2.waitKey(0)
However it shows a blank image , Any ideas?
原文:https://stackoverflow.com/questions/14422704
更新时间:2023-05-22 08:05
最满意答案
看看这个演示。 删除后应立即存储
@@rowcount
。 正如ZLK在他的评论中所说,@@rowcount
将被包括IF在内的任何其他Sql语句重置。create table demo (n int); insert demo(n) values (1), (2); declare @rc int =-1; delete from demo where n=1; set @rc = @@rowcount; if (@@error = 0) -- this will reset @@rowcount select @rc, @@rowcount -- returns 1, 0
Look at this demo. You should store
@@rowcount
immediately after delete. As ZLK said in his comment@@rowcount
will be reset by any other Sql statement including IF.create table demo (n int); insert demo(n) values (1), (2); declare @rc int =-1; delete from demo where n=1; set @rc = @@rowcount; if (@@error = 0) -- this will reset @@rowcount select @rc, @@rowcount -- returns 1, 0
相关问答
更多-
它以整数除法结束。 所以 15/45 = 0 尝试将至少一个操作数CAST到十进制中, SELECT CEILING((17-2)/CAST(45 AS DECIMAL (4,2)) 或者喜欢, SELECT CEILING(15,45.0) It ended with a integer division. So 15/45 = 0 Try CASTing atleast one of the operand into decimal , SELECT CEILING((17-2)/CAST(45 A ...
-
您可能(如果只是转向并在CLR过程中运行一段SQL)是想调用ExecuteAndSend 除了任何实际结果外,其他消息和错误也会直接发送给客户端。 SqlCommand command = new SqlCommand("update update_dummy set value = value + 1 where id = 1", conn); conn.Open(); SqlContext.Pipe.ExecuteAndSend(command); You probably (if it makes ...
-
将@@ rowcount分配给SQL Server存储过程中的变量(Assigning @@rowcount to variable in SQL Server stored procedure)[2022-11-30]
您的if语句可能正在重置@@rowcount 。 首先存储值,然后测试它: select ... from ... set @rowsAffected = @@rowcount if @rowsAffected = 0 set @rowsAffected = -1 Your if statement is probably resetting @@rowcount. First store the value, then test it: select ... from ... set ... -
你可能正在尝试做这样的事情。 请注意,即使在PL / SQL块中(无论是存储过程还是匿名过程),您也不能在INSERT语句中使用SQL%ROWCOUNT ; 你必须创建一个变量,为它分配计数,并在INSERT使用该变量。 create table mytbl (id number, mycondition number); insert into mytbl select 101, 1 from dual union all select 102, 2 from dual union all ...
-
@@Rowcount是一个特殊变量。 它将始终保存最后一个语句更改或返回的记录数。 在这种情况下,最后一个语句是插入。 通过在where子句中使用@@Rowcount > 0 ,可以确保select仅在insert语句成功时匹配任何记录。 如果他们使用了@@Rowcount > 1 ,那么该语句永远不会成立。 该insert语句只插入1行。 1不是> 1。 @@Rowcount is a special variable. It will always hold the number of records ...
-
地球表面上的任何闭合线都可以描述两个不同的有限空间中的一个。 为了知道正在定义哪个空间,您需要确定形状的“内部”的位置。 在这种情况下,G1目前描述地球的大部分减去大约-90.066,35.513周围的少量空间。 如果您希望它描述包含 -90.066,35.513的地球的一小部分,那么您需要更改用于描述形状的点的序列: DECLARE @g1 GEOGRAPHY; DECLARE @g2 GEOGRAPHY; SET @g1 = geography::STGeomFromText('POLYGON(( ...
-
看看这个演示。 删除后应立即存储@@rowcount 。 正如ZLK在他的评论中所说, @@rowcount将被包括IF在内的任何其他Sql语句重置。 create table demo (n int); insert demo(n) values (1), (2); declare @rc int =-1; delete from demo where n=1; set @rc = @@rowcount; if (@@error = 0) -- this will reset @@rowcount ...
-
AFAIK在postgresql中没有这样的构造,但是行数是你从postgresql获得的结果的一部分。 使用libpq时: 在select的结果上,您可以使用PQntuples来确定返回的行数。 对于更新,插入和删除,您可以使用PQcmdTuples和结果来获取受影响的行数。 AFAIK there is no such construct in postgresql however the number of rows is part of the result you get from postgre ...
-
你可以在这里找到rowCount的文档: http : //php.net/manual/en/pdostatement.rowcount.php 你有什么其他的结果会阻止你只选择具有这种条件的行吗?: SELECT id, building_name FROM campus WHERE building_name = 'IT House' 更好的是你可以选择计数: SELECT COUNT(*) FROM campus WHERE building_name = 'IT House' 否则,您必须遍历 ...
-
为什么SQL rowcount没有在我的存储过程输出参数中返回?(Why is SQL rowcount not returning in my stored procedure output parameter?)[2022-02-10]
执行过程时附加OUTPUT关键字: DECLARE @returnCode INT EXEC myProcedure 1, 1, @returnCode OUTPUT SELECT @returnCode Append OUTPUT Keyword when executing the Procedure: DECLARE @returnCode INT EXEC myProcedure 1, 1, @returnCode OUTPUT SELECT @returnCode