I want to do a Master's in CS, but I didn't do the undergraduate in CS, so I want to know if I can get a letter of recommendation from a professor that I know but who didn't actually teach me.
The general rule when it comes to letters of recommendation is that you should not ask for a letter from someone who does not know you well.
In this particular case, it's not sufficient that the professor you want to ask knows you. It is more important that he knows your work well, and can comment on that to graduate schools regarding your potential as a future student in their program.
You can get a letter from anyone who is willing to write one for you. They will normally only say they will write the letter if they know something about you. I've personally written letters a few times for students who had problems with their dissertation supervisor, and I knew something about their work for one reason or another, e.g. they'd tutored for me, I'd second marked their (undergraduate) dissertation, they've turned up regularly to research seminars and asked good questions or even given a talk, they've done research with me or my PhD students. Actually, some of those can be more important than having taken a class with someone.
If someone asks me for a letter and I don't know them, if they just ask me because I'm well known in my field, and they can't say why they want me to write the letter, then I will tell them I can't write a strong letter. If I have time and they still insist, I write a letter that says "I can confirm that this is a student at my university, their GPA is [whatever, I look it up], and I have no idea why they asked me to write this letter." Depending what you need the letter for, it's possible that would be enough.
A better plan would be to exploit office hours, sign up and visit a few times, discuss (first read!) their papers, and then asks for a letter. Then the letter might be made stronger by the impression you've made.
Keep in mind the overall goal -- you want to convince the admissions committee that you're a great student, and would do well in their program.
Of course you can point out your own strengths yourself, but it's even better if someone they trust testifies to your strengths. If the person your asking hasn't seen your strengths personally, they won't be able to write a personal letter attesting to them.
So get to know people, either by going to office hours (as said above), taking a class, taking up a side project, or working for them.
If you want to stick with people you already know, you should be aware yourself about how your background in ___ prepared you for a CS degree, or shows you're likely to succeed. If you can let the recommenders know how they can help and why you chose them, they might realize they can help rather than thinking they cant.