matrix

Opencv matrix values display

二次信任 提交于 2020-01-02 03:25:37
问题 here's the problem: I load an grayscale Image with OpenCV v.2.4.2. Now I want to know for example value of pixel at position (0,0). I've tried: Mat image=imread("00001.jpg",1); cvtColor(image,image,CV_RGB2GRAY); int a=image.at<unsigned>(0,1); printf("%d ",a); This actually doesn't work. How to get the pixel value with any data type (CV_8U, CV_32S ...)? Thanks!!! 回答1: You are making two mistakes here. While reading the image, you are specifying 1 as input arguments. As explained for imread,

convert dictionary to sparse matrix

一个人想着一个人 提交于 2020-01-02 01:37:50
问题 I have a dictionary with keys as user_ids and values as list of movie_ids liked by that user with #unique_users = 573000 and # unique_movies =16000. {1: [51, 379, 552, 2333, 2335, 4089, 4484], 2: [51, 379, 552, 1674, 1688, 2333, 3650, 4089, 4296, 4484], 5: [783, 909, 1052, 1138, 1147, 2676], 7: [171, 321, 959], 9: [3193], 10: [959], 11: [131,567,897,923],..........} Now i want to convert this into into a matrix with rows as user_ids and columns as movies_id with values 1 for the movies which

How do I extract rownames from a matrix?

时间秒杀一切 提交于 2020-01-02 01:21:10
问题 I have a matrix with rownames that are dates. I want to extract these row names into a variable, and then use rownames() to apply these dates to another matrix I have. Let's say the matrix is called 'data.matrix'. Whenever I run: data.matrix[,0] I get a printout of all the dates. So I do this: v <- data.matrix[,0] When I return v I get a nice list of all the dates. But when I use: rownames(other.matrix) <- v And then I return: head(other.matrix) I don't get any new column names. Also, when I

Getting all the diagonals of a matrix in Haskell

隐身守侯 提交于 2020-01-02 01:11:12
问题 The two-dimensional list looks like: 1 | 2 | 3 - - - - - 4 | 5 | 6 - - - - - 7 | 8 | 9 Or in pure haskell [ [1,2,3], [4,5,6], [7,8,9] ] The expected output for diagonals [ [1,2,3], [4,5,6], [7,8,9] ] is [ [1], [4, 2], [7, 5, 3], [8, 6], [9] ] Writing allDiagonals (to include anti-diagonals) is then trivial: allDiagonals :: [[a]] -> [[a]] allDiagonals xss = (diagonals xss) ++ (diagonals (rotate90 xss)) My research on this problem Similar question here at StackOverflow Python this question is

Creating Identity Matrices in R

◇◆丶佛笑我妖孽 提交于 2020-01-02 00:53:25
问题 I'd like to create identity matrices of different sizes, and I'm able to do so on a smaller scale like so: > x <- matrix(cbind(c(1,0), c(0,1)), 2) > x [,1] [,2] [1,] 1 0 [2,] 0 1 And like so: > y <- matrix(cbind(c(1,0,0), c(0,1,0), c(0,0,1)), 3) > y [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 However, it seems this will become increasingly tedious as identity matrices increase in size. Is there an easier way to create n -value identity matrices? 回答1: one (two) of the uses for diag when

Maximum number of elements in the path of a matrix

左心房为你撑大大i 提交于 2020-01-01 19:46:09
问题 I tried to solve a problem of map (matrix 4x4) using python. I want to find Maximum number of elements in the path of a map provided the next node must be lesser than the previous node with all possible combinations of elements in the matrix. 4 8 7 3 2 5 9 3 6 3 2 5 4 4 1 6 The movement is like from an element can move to east-west-north-south For example from m[0][1] can move to m[0][2] and m[1][1] 4-> 8 or 2 Here is the sample code but i have no idea to how to recursively check every

What do I do with the fundamental matrix?

∥☆過路亽.° 提交于 2020-01-01 19:44:51
问题 I am trying to reconstruct a 3d shape from multiple 2d images. I have calculated a fundamental matrix, but now I don't know what to do with it. I am finding multiple conflicting answers on stack overflow and academic papers. For example, Here says you need to compute the rotation and translation matrices from the fundamental matrix. Here says you need to find the camera matrices. Here says you need to find the homographies. Here says you need to find the epipolar lines. Which is it?? (And how

How to rotate the image without changing its size?

人盡茶涼 提交于 2020-01-01 18:54:33
问题 I am developing an android app where I have to rotate a circular image around another circular image, but when I am running this the size of my circular image gets automatically changing continuously. So please help me how to solve this. Here is my code public class JobSearch extends Activity implements OnTouchListener { private ImageView dialer; private float y=0; public boolean onTouch(View v, MotionEvent event) { double r=Math.atan2(event.getX()-dialer.getWidth()/2, dialer.getHeight()/2

How to rotate the image without changing its size?

試著忘記壹切 提交于 2020-01-01 18:53:49
问题 I am developing an android app where I have to rotate a circular image around another circular image, but when I am running this the size of my circular image gets automatically changing continuously. So please help me how to solve this. Here is my code public class JobSearch extends Activity implements OnTouchListener { private ImageView dialer; private float y=0; public boolean onTouch(View v, MotionEvent event) { double r=Math.atan2(event.getX()-dialer.getWidth()/2, dialer.getHeight()/2

Writing a Householder QR factorization function in R code

╄→尐↘猪︶ㄣ 提交于 2020-01-01 18:20:13
问题 I am working on a piece of code to find the QR factorization of a matrix in R. X <- structure(c(0.8147, 0.9058, 0.127, 0.9134, 0.6324, 0.0975, 0.2785, 0.5469, 0.9575, 0.9649, 0.1576, 0.9706, 0.9572, 0.4854, 0.8003 ), .Dim = c(5L, 3L)) myqr <- function(A) { n <- nrow(A) p <- ncol(A) Q <- diag(n) Inp <- diag(nrow = n, ncol = p) for(k in c(1:ncol(A))) { # extract the kth column of the matrix col<-A[k:n,k] # calculation of the norm of the column in order to create the vector norm1<-sqrt(sum(col^2